Spaces:
Sleeping
Sleeping
File size: 1,211 Bytes
e4f474e 481894e 310ee83 e4f474e 310ee83 c5fe059 e4f474e 310ee83 c5fe059 310ee83 481894e 310ee83 c5fe059 1bb62bf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import os
import gradio as gr
import subprocess
import zipfile
model_dir = "trained_model"
zip_path = "trained_model.zip"
def model_exists():
return os.path.exists(zip_path)
def train_model():
result = subprocess.run(["python", "train.py"], capture_output=True, text=True)
if result.returncode == 0 and os.path.exists(zip_path):
return "β
Model trained successfully! Ready for download.", zip_path
else:
return f"β Training failed:\n\n{result.stderr}", None
with gr.Blocks() as demo:
gr.Markdown("## π§ Python AI Model Trainer")
if model_exists():
gr.Markdown("β
Trained model found. Click below to download:")
gr.File(value=zip_path, label="Download Trained Model")
else:
gr.Markdown("π« No trained model found yet.")
output = gr.Textbox(label="Training Log")
download = gr.File(visible=False)
train_button = gr.Button("π Train Model")
def on_click_train():
message, path = train_model()
return message, gr.update(value=path, visible=True) if path else gr.update(visible=False)
train_button.click(fn=on_click_train, outputs=[output, download])
demo.launch() |