sonisatish119 commited on
Commit
55ccd60
·
verified ·
1 Parent(s): 81f0a25

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -2,17 +2,35 @@ import gradio as gr
2
  from transformers import pipeline
3
 
4
  # Load the trained intent classification model
5
- model_name = "sonisatish119/PhysioMindAI-intent-classification-bert" # Replace with your actual model name
6
  classifier = pipeline("text-classification", model=model_name)
7
 
8
- # Define a function to predict intent
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  def predict_intent(query):
10
  result = classifier(query)
11
- intent = result[0]["label"]
12
  confidence = result[0]["score"]
 
 
 
 
13
  return f"Intent: {intent} (Confidence: {confidence:.2f})"
14
 
15
- # Create Gradio Interface
16
  demo = gr.Interface(
17
  fn=predict_intent,
18
  inputs=gr.Textbox(placeholder="Type your query here...", lines=2),
 
2
  from transformers import pipeline
3
 
4
  # Load the trained intent classification model
5
+ model_name = "sonisatish119/PhysioMindAI-intent-classification-bert"
6
  classifier = pipeline("text-classification", model=model_name)
7
 
8
+ # Define intent label mapping
9
+ intent_labels = {
10
+ "LABEL_0": "book_appointment",
11
+ "LABEL_1": "reschedule_appointment",
12
+ "LABEL_2": "cancel_appointment",
13
+ "LABEL_3": "check_appointment_status",
14
+ "LABEL_4": "available_slots_inquiry",
15
+ "LABEL_5": "appointment_reminder",
16
+ "LABEL_6": "appointment_requirements",
17
+ "LABEL_7": "emergency_booking",
18
+ "LABEL_8": "appointment_location_details",
19
+ "LABEL_9": "modify_appointment_details",
20
+ }
21
+
22
+ # Function to predict intent
23
  def predict_intent(query):
24
  result = classifier(query)
25
+ label = result[0]["label"] # This will be "LABEL_0", "LABEL_1", etc.
26
  confidence = result[0]["score"]
27
+
28
+ # Map label to actual intent name
29
+ intent = intent_labels.get(label, "Unknown Intent")
30
+
31
  return f"Intent: {intent} (Confidence: {confidence:.2f})"
32
 
33
+ # Gradio Interface
34
  demo = gr.Interface(
35
  fn=predict_intent,
36
  inputs=gr.Textbox(placeholder="Type your query here...", lines=2),