Percy3822 commited on
Commit
6600b62
Β·
verified Β·
1 Parent(s): 078d71d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
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 the generator model once at the top (for better performance)
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.", None
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 # βœ… Fix warning and enforce consistent length
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
- download_btn = gr.File(label="πŸ“₯ Download Trained Model", visible=False)
 
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
- start_btn.click(fn=read_logs, outputs=log_output)
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")