Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
-
# Define a dictionary of
|
| 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 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
message = message.lower()
|
| 31 |
|
| 32 |
-
# Check for
|
| 33 |
if message in dental_terms:
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
closest_match, score = process.extractOne(message, dental_terms.keys())
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
else:
|
| 41 |
-
return "I'm sorry, I
|
| 42 |
|
| 43 |
-
# Set up
|
| 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",
|