Add a evaluation file viewer tab using dropdown and textbox
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from train_abuse_model import (
|
| 3 |
run_training,
|
| 4 |
evaluate_saved_model,
|
|
@@ -34,17 +35,29 @@ with gr.Blocks() as demo:
|
|
| 34 |
inputs=[desc_input, chat_upload],
|
| 35 |
outputs=[enriched_output, label_output]
|
| 36 |
)
|
| 37 |
-
with gr.Tab("π Evaluation Viewer"):
|
| 38 |
-
file_selector = gr.File(label="Select a report file")
|
| 39 |
-
preview_box = gr.Textbox(label="π File Preview", lines=20)
|
| 40 |
|
| 41 |
-
def load_eval_file(file_obj):
|
| 42 |
-
if file_obj is None:
|
| 43 |
-
return "No file selected."
|
| 44 |
-
with open(file_obj.name, encoding="utf-8") as f:
|
| 45 |
-
return f.read()
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
from train_abuse_model import (
|
| 4 |
run_training,
|
| 5 |
evaluate_saved_model,
|
|
|
|
| 35 |
inputs=[desc_input, chat_upload],
|
| 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}"
|
| 47 |
+
if not os.path.exists(path):
|
| 48 |
+
return "β File not found."
|
| 49 |
+
with open(path, "r", encoding="utf-8") as f:
|
| 50 |
+
return f.read()
|
| 51 |
+
|
| 52 |
+
file_dropdown = gr.Dropdown(
|
| 53 |
+
choices=list_eval_files(),
|
| 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__":
|