|
import gradio as gr |
|
from setfit import SetFitModel |
|
|
|
|
|
model = SetFitModel.from_pretrained("CundK/ePA-Classifier-Agreement") |
|
|
|
|
|
label_mapping = {0: "Ablehnung", 1: "Neutral", 2: "Befürwortung"} |
|
|
|
|
|
color_mapping = { |
|
"Ablehnung": "red", |
|
"Neutral": "yellow", |
|
"Befürwortung": "green" |
|
} |
|
|
|
|
|
def classify_text(text): |
|
|
|
predictions = model([text]) |
|
|
|
|
|
label_index = int(predictions[0].item()) |
|
|
|
|
|
label = label_mapping[label_index] |
|
|
|
|
|
return f'<div style="background-color: {color_mapping[label]}; padding: 10px; border-radius: 5px;">{label}</div>' |
|
|
|
|
|
with gr.Blocks() as interface: |
|
gr.Markdown("# Text Classification with SetFit") |
|
gr.Markdown("Enter a sentence and get it classified into 'Ablehnung', 'Neutral', or 'Befürwortung'.") |
|
|
|
|
|
text_input = gr.Textbox(lines=2, placeholder="Enter your text here...", multiline=False) |
|
|
|
|
|
submit_btn = gr.Button("Submit") |
|
|
|
|
|
result_output = gr.HTML(value="<div style='color:gray;'>The classification result will be displayed here.</div>") |
|
|
|
|
|
submit_btn.click(fn=classify_text, inputs=text_input, outputs=result_output) |
|
|
|
|
|
text_input.submit(fn=classify_text, inputs=text_input, outputs=result_output) |
|
|
|
|
|
interface.launch() |