Download app.py from Satyam0077/CustomerSupportTicketClassifier: direct link, hf CLI and curl.
- Browser
- Download file 1.74 kB
-
https://huggingface.co/spaces/Satyam0077/CustomerSupportTicketClassifier/resolve/main/app.py
- Command line
-
hf download hf://spaces/Satyam0077/CustomerSupportTicketClassifier/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Satyam0077/CustomerSupportTicketClassifier/resolve/main/app.py
1.74 kB
| import gradio as gr | |
| from src.inference import predict_ticket # Uses the fixed inference.py with nltk fix | |
| def predict_interface(ticket_text): | |
| try: | |
| result = predict_ticket(ticket_text) | |
| issue = result.get("issue_type", "Unknown") | |
| urgency = result.get("urgency_level", "Unknown") | |
| entities = result.get("entities", {}) | |
| # Format entity output | |
| lines = [] | |
| for key in ["products", "dates", "complaints"]: | |
| vals = entities.get(key, []) | |
| lines.append(f"{key.capitalize()}: {', '.join(vals) if vals else 'None'}") | |
| entities_str = "\n".join(lines) | |
| return issue, urgency, entities_str | |
| except Exception as e: | |
| return f"Prediction error: {str(e)}", "Prediction error", "Prediction error" | |
| # Build the Gradio interface | |
| iface = gr.Interface( | |
| fn=predict_interface, | |
| inputs=gr.Textbox( | |
| label="π Customer Support Ticket", | |
| lines=6, | |
| placeholder=( | |
| "Describe your issue clearly.\n" | |
| "Example: 'I returned the washing machine on 10th May but no refund received.'" | |
| ) | |
| ), | |
| outputs=[ | |
| gr.Textbox(label="π Predicted Issue Type"), | |
| gr.Textbox(label="β±οΈ Predicted Urgency Level"), | |
| gr.Textbox(label="π§ Extracted Entities"), | |
| ], | |
| title="π¬ Customer Support Ticket Analyzer", | |
| description=( | |
| "Paste a customer support ticket. This tool uses machine learning to predict:\n\n" | |
| "- π Issue Type (e.g., Late Delivery, Refund)\n" | |
| "- β±οΈ Urgency Level (Low / Medium / High)\n" | |
| "- π§ Extracted Entities (Products, Dates, Complaints)" | |
| ), | |
| allow_flagging="never" | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |