Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
"""
|
4 |
+
Gradio app for R1-Distill-LLama-8b training interface.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import os
|
8 |
+
import sys
|
9 |
+
import json
|
10 |
+
import gradio as gr
|
11 |
+
import subprocess
|
12 |
+
from pathlib import Path
|
13 |
+
import logging
|
14 |
+
|
15 |
+
# Configure logging
|
16 |
+
logging.basicConfig(
|
17 |
+
level=logging.INFO,
|
18 |
+
format="%(asctime)s - %(levelname)s - %(message)s",
|
19 |
+
handlers=[logging.StreamHandler(sys.stdout)]
|
20 |
+
)
|
21 |
+
logger = logging.getLogger(__name__)
|
22 |
+
|
23 |
+
def load_config(config_path):
|
24 |
+
"""Load a JSON configuration file."""
|
25 |
+
try:
|
26 |
+
with open(config_path, 'r') as f:
|
27 |
+
return json.load(f)
|
28 |
+
except Exception as e:
|
29 |
+
logger.error(f"Error loading config from {config_path}: {e}")
|
30 |
+
return None
|
31 |
+
|
32 |
+
def start_training():
|
33 |
+
"""Start the training process."""
|
34 |
+
try:
|
35 |
+
# Check if training is already in progress
|
36 |
+
lock_file = Path("TRAINING_IN_PROGRESS.lock")
|
37 |
+
if lock_file.exists():
|
38 |
+
return "Training is already in progress. Please wait for it to complete."
|
39 |
+
|
40 |
+
# Start training script
|
41 |
+
cmd = [sys.executable, "run_transformers_training.py"]
|
42 |
+
process = subprocess.Popen(
|
43 |
+
cmd,
|
44 |
+
stdout=subprocess.PIPE,
|
45 |
+
stderr=subprocess.STDOUT,
|
46 |
+
universal_newlines=True
|
47 |
+
)
|
48 |
+
|
49 |
+
# Return immediate confirmation
|
50 |
+
return "Training started successfully! Check the logs for progress."
|
51 |
+
except Exception as e:
|
52 |
+
logger.error(f"Error starting training: {e}")
|
53 |
+
return f"Error starting training: {str(e)}"
|
54 |
+
|
55 |
+
def check_training_status():
|
56 |
+
"""Check the current status of training."""
|
57 |
+
try:
|
58 |
+
# Check lock file
|
59 |
+
lock_file = Path("TRAINING_IN_PROGRESS.lock")
|
60 |
+
if not lock_file.exists():
|
61 |
+
return "No training in progress"
|
62 |
+
|
63 |
+
# Read lock file content
|
64 |
+
with open(lock_file, 'r') as f:
|
65 |
+
status = f.read()
|
66 |
+
return f"Training in progress:\n{status}"
|
67 |
+
except Exception as e:
|
68 |
+
logger.error(f"Error checking training status: {e}")
|
69 |
+
return f"Error checking status: {str(e)}"
|
70 |
+
|
71 |
+
# Create Gradio interface
|
72 |
+
with gr.Blocks(title="R1-Distill-LLama-8b Training") as demo:
|
73 |
+
gr.Markdown("# R1-Distill-LLama-8b Training Interface")
|
74 |
+
gr.Markdown("This interface allows you to control and monitor the training process.")
|
75 |
+
|
76 |
+
with gr.Row():
|
77 |
+
start_btn = gr.Button("Start Training")
|
78 |
+
status_btn = gr.Button("Check Status")
|
79 |
+
|
80 |
+
output = gr.Textbox(label="Output", lines=5)
|
81 |
+
|
82 |
+
start_btn.click(start_training, outputs=output)
|
83 |
+
status_btn.click(check_training_status, outputs=output)
|
84 |
+
|
85 |
+
if __name__ == "__main__":
|
86 |
+
demo.launch()
|