Spaces:
Runtime error
Runtime error
| 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() | |