-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweb.py
More file actions
85 lines (65 loc) · 2.76 KB
/
web.py
File metadata and controls
85 lines (65 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import gradio as gr
from gradio_client import Client
from api import run_model
# Dummy classifier function
# Classify input
def classify_input(description, category, state):
if description:
return run_model(description, category, state)
return "Please fill in all required fields."
# Flag and return updated flagged list
def flag_result(description, category, state, result, flagged_data):
# Validate result is non-empty and matches inputs
expected_result = run_model(description, category, state)
if not result or result.strip() != expected_result.strip():
return gr.update(), flagged_data, "⚠️ Please click 'Submit' before flagging."
flagged_data.append([description, category, state, result])
return flagged_data, flagged_data, "" # Clear error
# Clear all flagged examples
def clear_flagged():
return [], [], ""
with gr.Blocks() as webserver:
gr.Markdown("## Automatic identification of responsible authorities for citizen appeals")
with gr.Row():
description_input = gr.Textbox(label="Description", lines=2)
category_input = gr.Dropdown(choices=["Verkehr", "Bildung", "Migration", "Umwelt", "Gesundheit", "Wirtschaft", "Digitalisierung", "Sicherheit"], label="Category")
state_input = gr.Dropdown(choices=['Sachsen', 'Niedersachsen', 'Thüringen', 'Bayern',
'Baden-Württemberg', 'Nordrhein-Westfalen', 'Sachsen-Anhalt',
'Brandenburg', 'Hessen', 'Rheinland-Pfalz',
'Mecklenburg-Vorpommern', 'Schleswig-Holstein', 'Berlin',
'Hamburg', 'Saarland', 'Bremen'], label="State")
result_output = gr.Textbox(label="Model Output", interactive=False)
error_output = gr.Markdown("") # <-- New error display
with gr.Row():
submit_button = gr.Button("Submit")
flag_button = gr.Button("Flag this result")
clear_button = gr.Button("Clear All Flagged Results")
flagged_table = gr.Dataframe(
headers=["Description", "Category", "State", "Result"],
label="Flagged Examples",
interactive=False
)
flagged_state = gr.State([])
# On Submit
submit_button.click(
fn=classify_input,
inputs=[description_input, category_input, state_input],
outputs=result_output,
api_name="classify_input"
)
# On Flag
flag_button.click(
fn=flag_result,
inputs=[description_input, category_input, state_input, result_output, flagged_state],
outputs=[flagged_table, flagged_state, error_output],
api_name="flag_result"
)
# On Clear
clear_button.click(
fn=clear_flagged,
inputs=[],
outputs=[flagged_table, flagged_state, error_output],
api_name="clear_flagged"
)
if __name__ == "__main__":
webserver.queue(api_open=True).launch()