WSLINMSAI commited on
Commit
9a866fc
·
verified ·
1 Parent(s): 23cc51f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -1,7 +1,7 @@
1
-
2
  import gradio as gr
 
3
 
4
- # Define a dictionary of 20 dental terminologies and their definitions
5
  dental_terms = {
6
  "cavity": "A cavity is a hole in a tooth caused by decay.",
7
  "gingivitis": "Gingivitis is the inflammation of the gums, often caused by plaque buildup.",
@@ -26,21 +26,31 @@ dental_terms = {
26
  }
27
 
28
  def chatbot_response(message, history):
29
- # Convert the message to lowercase for case-insensitive matching
 
 
 
 
30
  message = message.lower()
31
 
32
- # Check for an exact match
33
  if message in dental_terms:
34
- return dental_terms[message]
35
-
36
- # Use fuzzy matching for approximate matches
 
 
37
  closest_match, score = process.extractOne(message, dental_terms.keys())
38
- if score >= 80: # Adjust threshold for acceptable matches (80% similarity)
39
- return f"Did you mean '{closest_match}'? {dental_terms[closest_match]}"
 
 
 
 
40
  else:
41
- return "I'm sorry, I am just a simple chatbot, and I don't understand that term. Please try another dental term."
42
 
43
- # Set up the Gradio interface
44
  demo = gr.ChatInterface(
45
  chatbot_response,
46
  type="messages",
 
 
1
  import gradio as gr
2
+ from fuzzywuzzy import process # Use 'from rapidfuzz import process' if using RapidFuzz
3
 
4
+ # Define a dictionary of dental terminologies and their definitions
5
  dental_terms = {
6
  "cavity": "A cavity is a hole in a tooth caused by decay.",
7
  "gingivitis": "Gingivitis is the inflammation of the gums, often caused by plaque buildup.",
 
26
  }
27
 
28
  def chatbot_response(message, history):
29
+ # Debugging: Print inputs and intermediate outputs
30
+ print(f"User Input: {message}")
31
+ print(f"Chat History: {history}")
32
+
33
+ # Convert the message to lowercase
34
  message = message.lower()
35
 
36
+ # Check for exact match
37
  if message in dental_terms:
38
+ response = dental_terms[message]
39
+ print(f"Exact Match Response: {response}")
40
+ return response
41
+
42
+ # Fuzzy matching for approximate matches
43
  closest_match, score = process.extractOne(message, dental_terms.keys())
44
+ print(f"Closest Match: {closest_match}, Score: {score}")
45
+
46
+ if score >= 80:
47
+ response = f"Did you mean '{closest_match}'? {dental_terms[closest_match]}"
48
+ print(f"Fuzzy Match Response: {response}")
49
+ return response
50
  else:
51
+ return "I'm sorry, I don't understand that term. Please try another dental term."
52
 
53
+ # Set up Gradio interface
54
  demo = gr.ChatInterface(
55
  chatbot_response,
56
  type="messages",