samurai9776 commited on
Commit
279605a
·
verified ·
1 Parent(s): 1d6f1dd

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +90 -0
app.py ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
4
+
5
+ # Load the model
6
+ model_id = "samurai9776/thought-classifier"
7
+ classifier = pipeline(
8
+ "text-classification",
9
+ model=model_id,
10
+ device=0 if torch.cuda.is_available() else -1
11
+ )
12
+
13
+ def classify_thought(ai_utterance, cx_utterance):
14
+ """Classify if the conversation is complete or incomplete"""
15
+
16
+ if not ai_utterance or not cx_utterance:
17
+ return "Please enter both utterances", 0, 0
18
+
19
+ # Combine utterances with [SEP] token
20
+ text = f"{ai_utterance} [SEP] {cx_utterance}"
21
+
22
+ # Get prediction
23
+ results = classifier(text)
24
+
25
+ # Extract scores
26
+ scores = {r['label']: r['score'] for r in results}
27
+ complete_score = scores.get('COMPLETE', 0)
28
+ incomplete_score = scores.get('INCOMPLETE', 0)
29
+
30
+ # Determine prediction
31
+ prediction = "Complete ✓" if complete_score > incomplete_score else "Incomplete ⚠️"
32
+
33
+ return prediction, complete_score, incomplete_score
34
+
35
+ # Create Gradio interface
36
+ with gr.Blocks(title="Thought Completion Classifier", theme=gr.themes.Soft()) as demo:
37
+ gr.Markdown("""
38
+ # 🤖 Thought Completion Classifier
39
+
40
+ This model determines if a conversation between an AI assistant and a customer represents a **complete** or **incomplete** thought.
41
+
42
+ Enter both utterances below and click "Classify" to see the results.
43
+ """)
44
+
45
+ with gr.Row():
46
+ with gr.Column():
47
+ ai_input = gr.Textbox(
48
+ label="AI Utterance",
49
+ placeholder="e.g., What else can I get for you?",
50
+ lines=2
51
+ )
52
+ cx_input = gr.Textbox(
53
+ label="Customer Utterance",
54
+ placeholder="e.g., That's all for now",
55
+ lines=2
56
+ )
57
+
58
+ classify_btn = gr.Button("🔍 Classify", variant="primary", size="lg")
59
+
60
+ with gr.Column():
61
+ prediction = gr.Textbox(label="Prediction", interactive=False)
62
+ with gr.Row():
63
+ complete_score = gr.Number(label="Complete Score", precision=3, interactive=False)
64
+ incomplete_score = gr.Number(label="Incomplete Score", precision=3, interactive=False)
65
+
66
+ # Examples
67
+ gr.Examples(
68
+ examples=[
69
+ ["Great. Would you like anything else?", "Picking up on app order."],
70
+ ["What size would you like?", "Large please"],
71
+ ["Your total is $15.99", "Actually, let me add"],
72
+ ["Anything else I can get for you?", "No, that's it"],
73
+ ["How can I help you today?", "I need to place an order"],
74
+ ["Will that complete your order?", "Yes, that's everything"],
75
+ ],
76
+ inputs=[ai_input, cx_input],
77
+ outputs=[prediction, complete_score, incomplete_score],
78
+ fn=classify_thought,
79
+ cache_examples=True,
80
+ )
81
+
82
+ classify_btn.click(
83
+ fn=classify_thought,
84
+ inputs=[ai_input, cx_input],
85
+ outputs=[prediction, complete_score, incomplete_score]
86
+ )
87
+
88
+ # Launch the app
89
+ if __name__ == "__main__":
90
+ demo.launch()