Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,37 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
with gr.Blocks() as demo:
|
| 8 |
-
gr.Markdown("##
|
| 9 |
|
| 10 |
-
if
|
| 11 |
-
gr.Markdown("
|
| 12 |
-
gr.File(value=
|
| 13 |
else:
|
| 14 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|