Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ log_path = "train.log"
|
|
| 9 |
model_dir = "trained_model"
|
| 10 |
zip_file = "trained_model.zip"
|
| 11 |
|
| 12 |
-
# Try loading
|
| 13 |
try:
|
| 14 |
generator = pipeline("text-generation", model=model_dir, tokenizer="distilgpt2")
|
| 15 |
except:
|
|
@@ -32,9 +32,9 @@ def start_training():
|
|
| 32 |
|
| 33 |
if os.path.exists(model_dir):
|
| 34 |
shutil.make_archive("trained_model", "zip", model_dir)
|
| 35 |
-
return "β
Training complete!", zip_file
|
| 36 |
else:
|
| 37 |
-
return "β Training failed.",
|
| 38 |
|
| 39 |
def read_logs():
|
| 40 |
if os.path.exists(log_path):
|
|
@@ -51,7 +51,7 @@ def generate_response(prompt):
|
|
| 51 |
max_length=256,
|
| 52 |
do_sample=True,
|
| 53 |
temperature=0.7,
|
| 54 |
-
truncation=True
|
| 55 |
)[0]["generated_text"]
|
| 56 |
return result
|
| 57 |
except Exception as e:
|
|
@@ -67,11 +67,12 @@ with gr.Blocks() as app:
|
|
| 67 |
|
| 68 |
start_btn = gr.Button("π Start Training")
|
| 69 |
log_output = gr.Textbox(label="π Training Logs", lines=15)
|
| 70 |
-
|
|
|
|
| 71 |
|
| 72 |
upload_btn.click(fn=upload_file, inputs=file_input, outputs=status_box)
|
| 73 |
start_btn.click(fn=start_training, outputs=[status_box, download_btn])
|
| 74 |
-
|
| 75 |
|
| 76 |
with gr.Tab("π Test AI"):
|
| 77 |
gr.Markdown("## π‘ Try your trained Godot AI below")
|
|
|
|
| 9 |
model_dir = "trained_model"
|
| 10 |
zip_file = "trained_model.zip"
|
| 11 |
|
| 12 |
+
# Try loading model for test tab
|
| 13 |
try:
|
| 14 |
generator = pipeline("text-generation", model=model_dir, tokenizer="distilgpt2")
|
| 15 |
except:
|
|
|
|
| 32 |
|
| 33 |
if os.path.exists(model_dir):
|
| 34 |
shutil.make_archive("trained_model", "zip", model_dir)
|
| 35 |
+
return "β
Training complete!", os.path.abspath(zip_file)
|
| 36 |
else:
|
| 37 |
+
return "β Training failed.", ""
|
| 38 |
|
| 39 |
def read_logs():
|
| 40 |
if os.path.exists(log_path):
|
|
|
|
| 51 |
max_length=256,
|
| 52 |
do_sample=True,
|
| 53 |
temperature=0.7,
|
| 54 |
+
truncation=True
|
| 55 |
)[0]["generated_text"]
|
| 56 |
return result
|
| 57 |
except Exception as e:
|
|
|
|
| 67 |
|
| 68 |
start_btn = gr.Button("π Start Training")
|
| 69 |
log_output = gr.Textbox(label="π Training Logs", lines=15)
|
| 70 |
+
refresh_btn = gr.Button("π Refresh Logs")
|
| 71 |
+
download_btn = gr.DownloadButton(label="π₯ Download Trained Model", visible=False)
|
| 72 |
|
| 73 |
upload_btn.click(fn=upload_file, inputs=file_input, outputs=status_box)
|
| 74 |
start_btn.click(fn=start_training, outputs=[status_box, download_btn])
|
| 75 |
+
refresh_btn.click(fn=read_logs, outputs=log_output)
|
| 76 |
|
| 77 |
with gr.Tab("π Test AI"):
|
| 78 |
gr.Markdown("## π‘ Try your trained Godot AI below")
|