WSLINMSAI commited on
Commit
e2cf7d8
·
verified ·
1 Parent(s): f3ce746

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -26,7 +26,7 @@ dental_terms = {
26
  "occlusion": "Occlusion refers to the alignment and contact between teeth when the jaws close."
27
  }
28
 
29
- # Set up a gpt2-large pipeline
30
  generation_pipeline = pipeline(
31
  "text-generation",
32
  model="gpt2-large"
@@ -37,11 +37,8 @@ def chatbot_response(message, history):
37
  Hybrid response logic:
38
  1) Check if user input matches a known dental term (exactly or via fuzzy matching).
39
  2) If found or close match, return the definition from our dictionary.
40
- 3) Otherwise, use Flan-T5 to generate an open-ended response.
41
  """
42
- print(f"User Input: {message}")
43
- print(f"Chat History: {history}")
44
-
45
  # Normalize user input to lowercase for simpler matching
46
  user_input_lower = message.lower()
47
 
@@ -54,11 +51,13 @@ def chatbot_response(message, history):
54
  if score >= 80:
55
  return f"Did you mean '{closest_match}'? {dental_terms[closest_match]}"
56
 
57
- # 3) If no match or fuzzy match is too low, use Flan-T5 for generation
58
- # We'll prompt it directly with the user's message.
59
- # Adjust parameters as desired for creativity, length, etc.
60
- result = generation_pipeline(message, max_length=100, num_return_sequences=1)
61
- generated_text = result[0]["generated_text"]
 
 
62
  return generated_text
63
 
64
  # Gradio chat interface
@@ -67,7 +66,7 @@ demo = gr.ChatInterface(
67
  title="Hybrid Dental Terminology Chatbot",
68
  description=(
69
  "Enter a dental term to get its definition (20 known terms). "
70
- "If the term isn't recognized, Flan-T5 will respond."
71
  )
72
  )
73
 
 
26
  "occlusion": "Occlusion refers to the alignment and contact between teeth when the jaws close."
27
  }
28
 
29
+ # Set up a gpt2-large pipeline
30
  generation_pipeline = pipeline(
31
  "text-generation",
32
  model="gpt2-large"
 
37
  Hybrid response logic:
38
  1) Check if user input matches a known dental term (exactly or via fuzzy matching).
39
  2) If found or close match, return the definition from our dictionary.
40
+ 3) Otherwise, use GPT-2 to generate an open-ended response.
41
  """
 
 
 
42
  # Normalize user input to lowercase for simpler matching
43
  user_input_lower = message.lower()
44
 
 
51
  if score >= 80:
52
  return f"Did you mean '{closest_match}'? {dental_terms[closest_match]}"
53
 
54
+ # 3) If no match or fuzzy match is too low, use GPT-2 for generation
55
+ try:
56
+ result = generation_pipeline(message, max_length=100, num_return_sequences=1)
57
+ generated_text = result[0]["generated_text"]
58
+ except Exception as e:
59
+ generated_text = f"Error generating response: {str(e)}"
60
+
61
  return generated_text
62
 
63
  # Gradio chat interface
 
66
  title="Hybrid Dental Terminology Chatbot",
67
  description=(
68
  "Enter a dental term to get its definition (20 known terms). "
69
+ "If the term isn't recognized, GPT-2 will respond with a generated message."
70
  )
71
  )
72