File size: 1,013 Bytes
f69fd89
 
 
 
a6a0b40
f69fd89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

# Load your trained model
model_path = "mjpsm/excuses-classification-model"
classifier = pipeline("text-classification", model=model_path)

# Map numeric labels to readable form
id2label = {"LABEL_0": "not_excuse", "LABEL_1": "excuse"}

# Inference function
def classify_user_input(user_message):
    result = classifier(user_message)[0]
    label = id2label.get(result["label"], result["label"])
    confidence = round(result["score"] * 100, 2)
    return f"Prediction: {label}\nConfidence: {confidence}%"

# Gradio interface
demo = gr.Interface(
    fn=classify_user_input,
    inputs=gr.Textbox(
        lines=4, 
        placeholder="Type your excuse or message here...",
        label="Your Message"
    ),
    outputs=gr.Textbox(label="Classification Result"),
    title="🧠 Excuse Classifier",
    description="Type any message below and see if it's classified as an excuse or not.",
)

# Launch the app
if __name__ == "__main__":
    demo.launch()