Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
|
| 7 |
+
def run_training(model_name):
|
| 8 |
+
"""Execute the training script and save to Hub"""
|
| 9 |
+
if not model_name.strip():
|
| 10 |
+
return "❌ Please enter a model name!"
|
| 11 |
+
|
| 12 |
+
# Set environment variable for the script
|
| 13 |
+
os.environ['MODEL_NAME'] = model_name.strip()
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
# Run training script
|
| 17 |
+
process = subprocess.Popen(
|
| 18 |
+
[sys.executable, 'train.py'],
|
| 19 |
+
stdout=subprocess.PIPE,
|
| 20 |
+
stderr=subprocess.STDOUT,
|
| 21 |
+
universal_newlines=True,
|
| 22 |
+
bufsize=1
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
output = ""
|
| 26 |
+
while True:
|
| 27 |
+
line = process.stdout.readline()
|
| 28 |
+
if line:
|
| 29 |
+
output += line
|
| 30 |
+
print(line.strip()) # For real-time logs
|
| 31 |
+
if process.poll() is not None:
|
| 32 |
+
break
|
| 33 |
+
|
| 34 |
+
if process.returncode == 0:
|
| 35 |
+
output += f"\n\n✅ SUCCESS! Model saved to: https://huggingface.co/{model_name}"
|
| 36 |
+
else:
|
| 37 |
+
output += f"\n\n❌ Training failed with return code: {process.returncode}"
|
| 38 |
+
|
| 39 |
+
return output
|
| 40 |
+
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return f"❌ Error: {str(e)}"
|
| 43 |
+
|
| 44 |
+
# Gradio Interface
|
| 45 |
+
with gr.Blocks(title="RoBERTa CUAD Trainer") as demo:
|
| 46 |
+
gr.Markdown("""
|
| 47 |
+
# 🤖 RoBERTa CUAD Question Answering Trainer
|
| 48 |
+
|
| 49 |
+
This will train a RoBERTa model with LoRA on the CUAD dataset and save it to Hugging Face Hub.
|
| 50 |
+
|
| 51 |
+
**Instructions:**
|
| 52 |
+
1. Enter your desired model name (format: `your-username/model-name`)
|
| 53 |
+
2. Click "Start Training"
|
| 54 |
+
3. Wait ~20-30 minutes for training to complete
|
| 55 |
+
4. Your model will be saved and publicly available!
|
| 56 |
+
""")
|
| 57 |
+
|
| 58 |
+
with gr.Row():
|
| 59 |
+
with gr.Column():
|
| 60 |
+
model_name_input = gr.Textbox(
|
| 61 |
+
label="Model Name",
|
| 62 |
+
placeholder="your-username/roberta-cuad-qa",
|
| 63 |
+
info="This will be your model's name on Hugging Face Hub"
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
train_btn = gr.Button("🚀 Start Training", variant="primary", size="lg")
|
| 67 |
+
|
| 68 |
+
with gr.Column():
|
| 69 |
+
gr.Markdown("""
|
| 70 |
+
**Training Details:**
|
| 71 |
+
- Model: RoBERTa-base + LoRA
|
| 72 |
+
- Dataset: CUAD (2000 samples)
|
| 73 |
+
- Time: ~20-30 minutes
|
| 74 |
+
- GPU: T4 (free)
|
| 75 |
+
""")
|
| 76 |
+
|
| 77 |
+
output_box = gr.Textbox(
|
| 78 |
+
label="Training Output",
|
| 79 |
+
lines=25,
|
| 80 |
+
max_lines=50,
|
| 81 |
+
show_copy_button=True
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
train_btn.click(
|
| 85 |
+
fn=run_training,
|
| 86 |
+
inputs=model_name_input,
|
| 87 |
+
outputs=output_box,
|
| 88 |
+
show_progress=True
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
gr.Markdown("""
|
| 92 |
+
---
|
| 93 |
+
**Note:** Make sure your model name follows the format `username/model-name` and you have write permissions.
|
| 94 |
+
""")
|
| 95 |
+
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
+
demo.launch()
|