Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,4 +7,30 @@ model_path = "./results/checkpoint-25752" # <-- Make sure this path matches you
|
|
| 7 |
|
| 8 |
# Load tokenizer and model
|
| 9 |
tokenizer = RobertaTokenizer.from_pretrained(model_path)
|
| 10 |
-
model = RobertaForSequenceClassification.from_pretrained(model_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Load tokenizer and model
|
| 9 |
tokenizer = RobertaTokenizer.from_pretrained(model_path)
|
| 10 |
+
model = RobertaForSequenceClassification.from_pretrained(model_path)
|
| 11 |
+
|
| 12 |
+
# Inference function: takes two sentences and returns classification
|
| 13 |
+
def detect_customer_complaint(premise, hypothesis):
|
| 14 |
+
inputs = tokenizer(premise, hypothesis, return_tensors="pt", truncation=True, padding=True, max_length=128)
|
| 15 |
+
outputs = model(**inputs)
|
| 16 |
+
pred = torch.argmax(outputs.logits, dim=1).item()
|
| 17 |
+
return label_map[pred]
|
| 18 |
+
|
| 19 |
+
# Assuming label mapping: 0 -> Costumer satisfied", 1 -> Neutral feedback, 2 -> Customer complaint
|
| 20 |
+
label_map = {0: "Costumer satisfied", 1: "Neutral feedback", 2: "Customer complaint"}
|
| 21 |
+
print("Predicted label:", label_map[predicted_label_idx])
|
| 22 |
+
|
| 23 |
+
# Gradio Interface setup
|
| 24 |
+
interface = gr.Interface(
|
| 25 |
+
fn=detect_customer_complaint,
|
| 26 |
+
inputs=[
|
| 27 |
+
gr.Textbox(lines=3, placeholder="Enter product description", label="Product Description"),
|
| 28 |
+
gr.Textbox(lines=3, placeholder="Enter customer feedback", label="Customer Feedback")
|
| 29 |
+
],
|
| 30 |
+
outputs=gr.Textbox(label="Prediction Result"),
|
| 31 |
+
title="Customer Complaint Detector",
|
| 32 |
+
description="Enter a product description and a customer feedback. The model will predict whether the feedback is a complaint, neutral, or satisfied."
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Launch the Gradio app
|
| 36 |
+
interface.launch()
|