Team Ai
Apppublic

ayush2917/Multi-Turn_Intent_Classification

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py34 linesDownload Raw Back to root
1import gradio as gr
2import json
3from models.intent_classifier import classify_conversation
4from utils.preprocessing import preprocess_messages
5from config import INTENT_LABELS
6
7def predict_intent(json_str):
8    try:
9        data = json.loads(json_str)
10        results = []
11        for conv in data:
12            messages = conv.get("messages", [])
13            cleaned = preprocess_messages(messages)
14            intent, rationale = classify_conversation(cleaned)
15            results.append({
16                "conversation_id": conv.get("conversation_id", "unknown"),
17                "predicted_intent": intent,
18                "rationale": rationale
19            })
20        return json.dumps(results, indent=2)
21    except Exception as e:
22        return f"❌ Error: {str(e)}"
23
24demo = gr.Interface(
25    fn=predict_intent,
26    inputs=gr.Textbox(label="Paste Chat JSON", lines=20, placeholder='[{"conversation_id": "...", "messages": [...] }]'),
27    outputs=gr.Textbox(label="Predicted Intents with Rationale"),
28    title="🧠 Multi-Turn Intent Classifier",
29    description="Paste WhatsApp-style chat logs to classify the final customer intent."
30)
31
32if __name__ == "__main__":
33    demo.launch()
34