Update app.py
Browse files25 unmodified lines262728293031324 unmodified lines37383940414243444546476 unmodified lines54555657585960616263642 unmodified lines6768697071727325 unmodified lines"occlusion": "Occlusion refers to the alignment and contact between teeth when the jaws close."}# Set up a gpt2-large pipelinegeneration_pipeline = pipeline("text-generation",model="gpt2-large"4 unmodified linesHybrid response logic:1) Check if user input matches a known dental term (exactly or via fuzzy matching).2) If found or close match, return the definition from our dictionary.3) Otherwise, use Flan-T5 to generate an open-ended response."""print(f"User Input: {message}")print(f"Chat History: {history}")# Normalize user input to lowercase for simpler matchinguser_input_lower = message.lower()6 unmodified linesif score >= 80:return f"Did you mean '{closest_match}'? {dental_terms[closest_match]}"# 3) If no match or fuzzy match is too low, use Flan-T5 for generation# We'll prompt it directly with the user's message.# Adjust parameters as desired for creativity, length, etc.result = generation_pipeline(message, max_length=100, num_return_sequences=1)generated_text = result[0]["generated_text"]return generated_text# Gradio chat interface2 unmodified linestitle="Hybrid Dental Terminology Chatbot",description=("Enter a dental term to get its definition (20 known terms). ""If the term isn't recognized, Flan-T5 will respond."))25 unmodified lines262728293031324 unmodified lines37383940414243446 unmodified lines515253545556575859606162632 unmodified lines6667686970717225 unmodified lines"occlusion": "Occlusion refers to the alignment and contact between teeth when the jaws close."}# Set up a gpt2-large pipelinegeneration_pipeline = pipeline("text-generation",model="gpt2-large"4 unmodified linesHybrid response logic:1) Check if user input matches a known dental term (exactly or via fuzzy matching).2) If found or close match, return the definition from our dictionary.3) Otherwise, use GPT-2 to generate an open-ended response."""# Normalize user input to lowercase for simpler matchinguser_input_lower = message.lower()6 unmodified linesif score >= 80:return f"Did you mean '{closest_match}'? {dental_terms[closest_match]}"# 3) If no match or fuzzy match is too low, use GPT-2 for generationtry:result = generation_pipeline(message, max_length=100, num_return_sequences=1)generated_text = result[0]["generated_text"]except Exception as e:generated_text = f"Error generating response: {str(e)}"return generated_text# Gradio chat interface2 unmodified linestitle="Hybrid Dental Terminology Chatbot",description=("Enter a dental term to get its definition (20 known terms). ""If the term isn't recognized, GPT-2 will respond with a generated message."))
app.py+10-11