File size: 1,223 Bytes
122270e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
from models.intent_classifier import classify_conversation
from utils.preprocessing import preprocess_messages
from config import INTENT_LABELS

def predict_intent(json_str):
    try:
        data = json.loads(json_str)
        results = []
        for conv in data:
            messages = conv.get("messages", [])
            cleaned = preprocess_messages(messages)
            intent, rationale = classify_conversation(cleaned)
            results.append({
                "conversation_id": conv.get("conversation_id", "unknown"),
                "predicted_intent": intent,
                "rationale": rationale
            })
        return json.dumps(results, indent=2)
    except Exception as e:
        return f"❌ Error: {str(e)}"

demo = gr.Interface(
    fn=predict_intent,
    inputs=gr.Textbox(label="Paste Chat JSON", lines=20, placeholder='[{"conversation_id": "...", "messages": [...] }]'),
    outputs=gr.Textbox(label="Predicted Intents with Rationale"),
    title="🧠 Multi-Turn Intent Classifier",
    description="Paste WhatsApp-style chat logs to classify the final customer intent."
)

if __name__ == "__main__":
    demo.launch()