Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
from models.intent_classifier import classify_conversation
|
| 4 |
+
from utils.preprocessing import preprocess_messages
|
| 5 |
+
from config import INTENT_LABELS
|
| 6 |
+
|
| 7 |
+
def 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 |
+
|
| 24 |
+
demo = 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 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
demo.launch()
|