|
|
import gradio as gr |
|
|
from fuzzywuzzy import process |
|
|
|
|
|
|
|
|
dental_terms = { |
|
|
"cavity": "A cavity is a hole in a tooth caused by decay.", |
|
|
"gingivitis": "Gingivitis is the inflammation of the gums, often caused by plaque buildup.", |
|
|
"implant": "A dental implant is a surgical component that interfaces with the jawbone to support a dental prosthesis.", |
|
|
"orthodontics": "Orthodontics is a branch of dentistry that corrects teeth and jaw alignment issues.", |
|
|
"plaque": "Plaque is a sticky, colorless film of bacteria that forms on teeth.", |
|
|
"enamel": "Enamel is the hard, outer surface layer of your teeth that protects against decay.", |
|
|
"braces": "Braces are orthodontic devices used to straighten teeth and correct bite issues.", |
|
|
"root canal": "A root canal is a treatment to repair and save a badly damaged or infected tooth.", |
|
|
"crown": "A crown is a dental cap placed over a tooth to restore its shape, size, and strength.", |
|
|
"veneers": "Veneers are thin shells placed over the front of teeth to improve appearance.", |
|
|
"halitosis": "Halitosis is chronic bad breath caused by bacteria or other factors.", |
|
|
"periodontitis": "Periodontitis is a serious gum infection that damages gums and can destroy the jawbone.", |
|
|
"denture": "Dentures are removable appliances that replace missing teeth and surrounding tissues.", |
|
|
"bridge": "A dental bridge is a fixed prosthetic device that replaces missing teeth.", |
|
|
"tartar": "Tartar is hardened plaque that forms on teeth and can only be removed by a dentist.", |
|
|
"x-ray": "A dental x-ray is an imaging technique used to view the inside of teeth and surrounding tissues.", |
|
|
"flossing": "Flossing is the process of cleaning between your teeth with dental floss.", |
|
|
"sealant": "A sealant is a protective coating applied to teeth to prevent decay.", |
|
|
"bitewing": "A bitewing is a type of dental x-ray that shows the upper and lower back teeth.", |
|
|
"occlusion": "Occlusion refers to the alignment and contact between teeth when the jaws close." |
|
|
} |
|
|
|
|
|
def chatbot_response(message, history): |
|
|
|
|
|
print(f"User Input: {message}") |
|
|
print(f"Chat History: {history}") |
|
|
|
|
|
|
|
|
message = message.lower() |
|
|
|
|
|
|
|
|
if message in dental_terms: |
|
|
response = dental_terms[message] |
|
|
print(f"Exact Match Response: {response}") |
|
|
return response |
|
|
|
|
|
|
|
|
closest_match, score = process.extractOne(message, dental_terms.keys()) |
|
|
print(f"Closest Match: {closest_match}, Score: {score}") |
|
|
|
|
|
if score >= 80: |
|
|
response = f"Did you mean '{closest_match}'? {dental_terms[closest_match]}" |
|
|
print(f"Fuzzy Match Response: {response}") |
|
|
return response |
|
|
else: |
|
|
return "I'm sorry, I don't understand that term. Please try another dental term." |
|
|
|
|
|
|
|
|
demo = gr.ChatInterface( |
|
|
chatbot_response, |
|
|
type="messages", |
|
|
title="Dental Terminology Chatbot", |
|
|
description=( |
|
|
"Enter a dental term to get its definition. " |
|
|
"If you misspell a term, the chatbot will try to suggest the closest match." |
|
|
) |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|