Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines91011121213141516 unmodified lines323334353536373738394010 unmodified lines51525354545556579 unmodified lines67686970707172737474757677788 unmodified linesmodel_dir = "trained_model"zip_file = "trained_model.zip"
# Try loading the generator model once at the top (for better performance)# Try loading model for test tabtry: generator = pipeline("text-generation", model=model_dir, tokenizer="distilgpt2")except:16 unmodified lines
if os.path.exists(model_dir): shutil.make_archive("trained_model", "zip", model_dir) return "β
Training complete!", zip_file return "β
Training complete!", os.path.abspath(zip_file) else: return "β Training failed.", None return "β Training failed.", ""
def read_logs(): if os.path.exists(log_path):10 unmodified lines max_length=256, do_sample=True, temperature=0.7, truncation=True # β
Fix warning and enforce consistent length truncation=True )[0]["generated_text"] return result except Exception as e:9 unmodified lines
start_btn = gr.Button("π Start Training") log_output = gr.Textbox(label="π Training Logs", lines=15) refresh_btn = gr.Button("π Refresh Logs") download_btn = gr.File(label="π₯ Download Trained Model", visible=False) download_btn = gr.DownloadButton(label="π₯ Download Trained Model", visible=False)
upload_btn.click(fn=upload_file, inputs=file_input, outputs=status_box) start_btn.click(fn=start_training, outputs=[status_box, download_btn]) start_btn.click(fn=read_logs, outputs=log_output) refresh_btn.click(fn=read_logs, outputs=log_output)
with gr.Tab("π Test AI"): gr.Markdown("## π‘ Try your trained Godot AI below")app.py+7-6