r0m4k commited on
Commit
bec0fa2
·
verified ·
1 Parent(s): da1f7b5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import threading
4
+ import time
5
+
6
+ def run_training(model_name, progress=gr.Progress()):
7
+ progress(0, desc="Starting Training...")
8
+
9
+ command = ["python", "train.py", "--model_name", model_name]
10
+
11
+ # Start the training process
12
+ process = subprocess.Popen(
13
+ command,
14
+ stdout=subprocess.PIPE,
15
+ stderr=subprocess.STDOUT,
16
+ text=True,
17
+ bufsize=1,
18
+ universal_newlines=True
19
+ )
20
+
21
+ # Stream the output
22
+ output = ""
23
+ for line in process.stdout:
24
+ output += line
25
+ # Update progress based on keywords in the output
26
+ if "Starting training..." in line:
27
+ progress(0.1, desc="Training Started...")
28
+ elif "loss" in line:
29
+ progress(0.5, desc=line.strip())
30
+
31
+ yield output
32
+
33
+ process.wait()
34
+
35
+ if process.returncode == 0:
36
+ progress(1, desc="Training Complete!")
37
+ yield output + "\nTraining finished successfully!"
38
+ else:
39
+ yield output + f"\nTraining failed with error code {process.returncode}."
40
+
41
+
42
+ with gr.Blocks() as demo:
43
+ gr.Markdown("# Llama Model Fine-Tuning")
44
+ gr.Markdown("Select a model and click 'Start Fine-Tuning' to begin.")
45
+
46
+ models = [
47
+ 'meta-llama/Meta-Llama-3-8B-Instruct',
48
+ 'meta-llama/Meta-Llama-3-70B-Instruct',
49
+ 'meta-llama/Llama-3.3-70B-Instruct'
50
+ ]
51
+ model_dropdown = gr.Dropdown(models, label="Select Model to Fine-Tune", value='meta-llama/Meta-Llama-3-8B-Instruct')
52
+
53
+ start_button = gr.Button("Start Fine-Tuning")
54
+
55
+ output_textbox = gr.Textbox(label="Training Log", lines=20, interactive=False)
56
+
57
+ start_button.click(
58
+ fn=run_training,
59
+ inputs=[model_dropdown],
60
+ outputs=[output_textbox]
61
+ )
62
+
63
+ demo.launch()