fix: resolve model detection and evaluation dropdown issues in app
Browse files- app.py +5 -3
- train_abuse_model.py +0 -3
app.py
CHANGED
|
@@ -36,11 +36,10 @@ with gr.Blocks() as demo:
|
|
| 36 |
outputs=[enriched_output, label_output]
|
| 37 |
)
|
| 38 |
|
| 39 |
-
|
| 40 |
with gr.Tab("π View Evaluation Reports"):
|
| 41 |
def list_eval_files():
|
| 42 |
folder = "/home/user/app/results_eval"
|
| 43 |
-
return sorted(os.listdir(folder), reverse=True)
|
| 44 |
|
| 45 |
def load_eval_file(filename):
|
| 46 |
path = f"/home/user/app/results_eval/{filename}"
|
|
@@ -50,15 +49,18 @@ with gr.Blocks() as demo:
|
|
| 50 |
return f.read()
|
| 51 |
|
| 52 |
file_dropdown = gr.Dropdown(
|
| 53 |
-
choices=
|
| 54 |
label="π Select an evaluation file",
|
| 55 |
interactive=True
|
| 56 |
)
|
|
|
|
| 57 |
report_output = gr.Textbox(label="π Evaluation Report", lines=20)
|
| 58 |
|
|
|
|
| 59 |
file_dropdown.change(fn=load_eval_file, inputs=file_dropdown, outputs=report_output)
|
| 60 |
|
| 61 |
|
| 62 |
|
|
|
|
| 63 |
if __name__ == "__main__":
|
| 64 |
demo.launch()
|
|
|
|
| 36 |
outputs=[enriched_output, label_output]
|
| 37 |
)
|
| 38 |
|
|
|
|
| 39 |
with gr.Tab("π View Evaluation Reports"):
|
| 40 |
def list_eval_files():
|
| 41 |
folder = "/home/user/app/results_eval"
|
| 42 |
+
return sorted(os.listdir(folder), reverse=True) if os.path.exists(folder) else []
|
| 43 |
|
| 44 |
def load_eval_file(filename):
|
| 45 |
path = f"/home/user/app/results_eval/{filename}"
|
|
|
|
| 49 |
return f.read()
|
| 50 |
|
| 51 |
file_dropdown = gr.Dropdown(
|
| 52 |
+
choices=[],
|
| 53 |
label="π Select an evaluation file",
|
| 54 |
interactive=True
|
| 55 |
)
|
| 56 |
+
refresh_btn = gr.Button("π Refresh File List")
|
| 57 |
report_output = gr.Textbox(label="π Evaluation Report", lines=20)
|
| 58 |
|
| 59 |
+
refresh_btn.click(fn=lambda: gr.Dropdown.update(choices=list_eval_files()), outputs=file_dropdown)
|
| 60 |
file_dropdown.change(fn=load_eval_file, inputs=file_dropdown, outputs=report_output)
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
+
|
| 65 |
if __name__ == "__main__":
|
| 66 |
demo.launch()
|
train_abuse_model.py
CHANGED
|
@@ -300,9 +300,6 @@ def run_training(progress=gr.Progress(track_tqdm=True)):
|
|
| 300 |
progress(1.0)
|
| 301 |
yield "β
Progress: 100%\n"
|
| 302 |
|
| 303 |
-
PERSIST_DIR = Path("/home/user/app")
|
| 304 |
-
MODEL_DIR = PERSIST_DIR / "saved_model"
|
| 305 |
-
|
| 306 |
# Save the model and tokenizer
|
| 307 |
MODEL_DIR.mkdir(parents=True, exist_ok=True)
|
| 308 |
model.save_pretrained(MODEL_DIR)
|
|
|
|
| 300 |
progress(1.0)
|
| 301 |
yield "β
Progress: 100%\n"
|
| 302 |
|
|
|
|
|
|
|
|
|
|
| 303 |
# Save the model and tokenizer
|
| 304 |
MODEL_DIR.mkdir(parents=True, exist_ok=True)
|
| 305 |
model.save_pretrained(MODEL_DIR)
|