darrenphodgson76 commited on
Commit
ab7bca8
·
verified ·
1 Parent(s): f47057d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -17
app.py CHANGED
@@ -2,27 +2,22 @@ import gradio as gr
2
  import subprocess
3
  import os
4
 
5
- def run_training():
6
- # Run train.py and capture logs
7
  result = subprocess.run(["python", "train.py"], capture_output=True, text=True)
8
-
9
- # Check for zipped model
10
  zip_path = "/home/user/app/model.zip"
11
  if os.path.exists(zip_path):
12
- result_msg = "\n✅ Model was successfully zipped to model.zip.\n"
13
- result_msg += "📥 You can download it from the Files tab or this URL:\n"
14
- result_msg += "https://huggingface.co/spaces/darrenphodgson76/SmolLM2-1.7B-Instruct-Bussiness-Analysis/+/blob/main/model.zip\n"
15
  else:
16
- result_msg = "\n❌ model.zip not found. Check logs below for issues.\n"
17
-
18
- return result.stdout + "\n" + result.stderr + result_msg
19
 
20
- iface = gr.Interface(
21
- fn=run_training,
22
  inputs=[],
23
- outputs="text",
24
  title="LLaMA LoRA Fine-Tuning",
25
- description="Click the button below to start fine-tuning the model using PEFT/LoRA. The fine-tuned model will be saved as a ZIP for download."
26
- )
27
-
28
- iface.launch()
 
2
  import subprocess
3
  import os
4
 
5
+ def run_training_and_return_zip():
6
+ # Run training and capture logs
7
  result = subprocess.run(["python", "train.py"], capture_output=True, text=True)
8
+
 
9
  zip_path = "/home/user/app/model.zip"
10
  if os.path.exists(zip_path):
11
+ logs = result.stdout + "\n" + result.stderr + "\nTraining complete. Download your model below."
12
+ return logs, zip_path
 
13
  else:
14
+ logs = result.stdout + "\n" + result.stderr + "\n❌ model.zip not found. Check logs for issues."
15
+ return logs, None
 
16
 
17
+ gr.Interface(
18
+ fn=run_training_and_return_zip,
19
  inputs=[],
20
+ outputs=["text", "file"],
21
  title="LLaMA LoRA Fine-Tuning",
22
+ description="Click the button to fine-tune. After training, download the zipped model directly."
23
+ ).launch()