samurai9776 commited on
Commit
670b056
·
verified ·
1 Parent(s): 19f6906

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +65 -19
app.py CHANGED
@@ -1,44 +1,90 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
3
 
4
- # Load the clean v2 model
 
5
  classifier = pipeline(
6
- "text-classification",
7
- model="samurai9776/thought-classifier-menu-aware"
 
8
  )
9
 
10
  def classify_thought(ai_utterance, cx_utterance):
 
 
11
  if not ai_utterance or not cx_utterance:
12
  return "Please enter both utterances", 0, 0
13
-
 
14
  text = f"{ai_utterance} [SEP] {cx_utterance}"
 
 
15
  results = classifier(text)
16
-
 
17
  scores = {r['label']: r['score'] for r in results}
18
  complete_score = scores.get('COMPLETE', 0)
19
  incomplete_score = scores.get('INCOMPLETE', 0)
20
-
 
21
  prediction = "Complete ✓" if complete_score > incomplete_score else "Incomplete ⚠️"
 
22
  return prediction, complete_score, incomplete_score
23
 
24
- with gr.Blocks(title="Thought Classifier v2") as demo:
25
- gr.Markdown("# 🤖 Thought Completion Classifier v2")
26
-
 
 
 
 
 
 
 
27
  with gr.Row():
28
  with gr.Column():
29
- ai_input = gr.Textbox(label="AI Utterance", placeholder="What sandwich?")
30
- cx_input = gr.Textbox(label="Customer Utterance", placeholder="Chicken")
31
- classify_btn = gr.Button("Classify", variant="primary")
32
-
 
 
 
 
 
 
 
 
 
33
  with gr.Column():
34
- prediction = gr.Textbox(label="Prediction")
35
- complete_score = gr.Number(label="Complete Score")
36
- incomplete_score = gr.Number(label="Incomplete Score")
37
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  classify_btn.click(
39
- classify_thought,
40
  inputs=[ai_input, cx_input],
41
  outputs=[prediction, complete_score, incomplete_score]
42
  )
43
 
44
- demo.launch()
 
 
 
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()