mjpsm commited on
Commit
f69fd89
·
verified ·
1 Parent(s): 578d4f4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load your trained model
5
+ model_path = "./excuse_nonexcuse_classifier_model"
6
+ classifier = pipeline("text-classification", model=model_path)
7
+
8
+ # Map numeric labels to readable form
9
+ id2label = {"LABEL_0": "not_excuse", "LABEL_1": "excuse"}
10
+
11
+ # Inference function
12
+ def classify_user_input(user_message):
13
+ result = classifier(user_message)[0]
14
+ label = id2label.get(result["label"], result["label"])
15
+ confidence = round(result["score"] * 100, 2)
16
+ return f"Prediction: {label}\nConfidence: {confidence}%"
17
+
18
+ # Gradio interface
19
+ demo = gr.Interface(
20
+ fn=classify_user_input,
21
+ inputs=gr.Textbox(
22
+ lines=4,
23
+ placeholder="Type your excuse or message here...",
24
+ label="Your Message"
25
+ ),
26
+ outputs=gr.Textbox(label="Classification Result"),
27
+ title="🧠 Excuse Classifier",
28
+ description="Type any message below and see if it's classified as an excuse or not.",
29
+ )
30
+
31
+ # Launch the app
32
+ if __name__ == "__main__":
33
+ demo.launch()