Percy3822 commited on
Commit
310ee83
Β·
verified Β·
1 Parent(s): 481894e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -7
app.py CHANGED
@@ -1,16 +1,37 @@
1
  import os
2
  import gradio as gr
 
 
3
 
4
- # Check for trained model zip
5
- model_zip = "trained_model.zip"
 
 
 
 
 
 
 
 
 
 
6
 
7
  with gr.Blocks() as demo:
8
- gr.Markdown("## πŸ€– Python AI Model Trainer")
9
 
10
- if os.path.exists(model_zip):
11
- gr.Markdown("### βœ… Model trained! Click below to download:")
12
- gr.File(value=model_zip, label="Download trained model")
13
  else:
14
- gr.Markdown("### 🚫 No trained model found yet. Run train.py to train it.")
 
 
 
 
 
 
 
 
 
15
 
16
  demo.launch()
 
1
  import os
2
  import gradio as gr
3
+ import subprocess
4
+ import zipfile
5
 
6
+ model_dir = "trained_model"
7
+ zip_path = "trained_model.zip"
8
+
9
+ def model_exists():
10
+ return os.path.exists(zip_path)
11
+
12
+ def train_model():
13
+ result = subprocess.run(["python", "train.py"], capture_output=True, text=True)
14
+ if result.returncode == 0 and os.path.exists(zip_path):
15
+ return "βœ… Model trained successfully! Ready for download.", zip_path
16
+ else:
17
+ return f"❌ Training failed:\n\n{result.stderr}", None
18
 
19
  with gr.Blocks() as demo:
20
+ gr.Markdown("## 🧠 Python AI Model Trainer")
21
 
22
+ if model_exists():
23
+ gr.Markdown("βœ… Trained model found. Click below to download:")
24
+ gr.File(value=zip_path, label="Download Trained Model")
25
  else:
26
+ gr.Markdown("🚫 No trained model found yet.")
27
+ output = gr.Textbox(label="Training Log")
28
+ download = gr.File(visible=False)
29
+ train_button = gr.Button("πŸš€ Train Model")
30
+
31
+ def on_click_train():
32
+ message, path = train_model()
33
+ return message, gr.update(value=path, visible=True) if path else gr.update(visible=False)
34
+
35
+ train_button.click(fn=on_click_train, outputs=[output, download])
36
 
37
  demo.launch()