mjpsm's picture
Update app.py
a6a0b40 verified
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()