Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load trained model
|
| 5 |
+
classifier = pipeline(
|
| 6 |
+
"text-classification",
|
| 7 |
+
model="King-8/request-classifier",
|
| 8 |
+
tokenizer="King-8/request-classifier",
|
| 9 |
+
return_all_scores=True
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
# Label mapping (MUST match training)
|
| 13 |
+
id_to_label = {
|
| 14 |
+
0: "administrative_action",
|
| 15 |
+
1: "attendance",
|
| 16 |
+
2: "check_in",
|
| 17 |
+
3: "clarification",
|
| 18 |
+
4: "general_chat",
|
| 19 |
+
5: "technical_help"
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
def classify_request(role, context, request):
|
| 23 |
+
text = f"Role: {role} | Context: {context} | Request: {request}"
|
| 24 |
+
|
| 25 |
+
outputs = classifier(text)[0]
|
| 26 |
+
|
| 27 |
+
# Get highest scoring label
|
| 28 |
+
best = max(outputs, key=lambda x: x["score"])
|
| 29 |
+
|
| 30 |
+
return {
|
| 31 |
+
"Predicted intent": best["label"],
|
| 32 |
+
"Confidence": round(best["score"], 3)
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
with gr.Blocks() as demo:
|
| 36 |
+
gr.Markdown("## Internship Request Classifier")
|
| 37 |
+
gr.Markdown(
|
| 38 |
+
"This demo uses a fine-tuned transformer model to classify internship-related requests "
|
| 39 |
+
"into routing categories such as attendance, check-ins, technical help, and more."
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
role = gr.Dropdown(
|
| 43 |
+
["student", "parent", "supervisor", "admin"],
|
| 44 |
+
label="User Role"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
context = gr.Textbox(
|
| 48 |
+
label="Conversation Context",
|
| 49 |
+
placeholder="e.g., No prior context or Earlier discussion about check-ins"
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
request = gr.Textbox(
|
| 53 |
+
label="User Request",
|
| 54 |
+
placeholder="e.g., I missed the Zoom meeting this morning"
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
output = gr.JSON(label="Model Output")
|
| 58 |
+
|
| 59 |
+
submit = gr.Button("Classify Request")
|
| 60 |
+
|
| 61 |
+
submit.click(
|
| 62 |
+
classify_request,
|
| 63 |
+
inputs=[role, context, request],
|
| 64 |
+
outputs=output
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
demo.launch()
|