chburhan64 commited on
Commit
53622e4
·
verified ·
1 Parent(s): dc4cd4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -14,6 +14,8 @@ breeds = {
14
  "Dog": ["German Shepherd", "Labrador", "Bulldog", "Pomeranian", "Other"]
15
  }
16
 
 
 
17
  def update_breeds(pet):
18
  options = breeds.get(pet, [])
19
  return gr.update(choices=options, visible=True, value=None), gr.update(visible=False, value="")
@@ -21,11 +23,15 @@ def update_breeds(pet):
21
  def show_custom_breed(breed_selected):
22
  return gr.update(visible=(breed_selected == "Other"), value="")
23
 
24
- def ask_ai(pet, breed, custom_breed, age, gender, weight, topic, symptom, condition, user_detail):
 
 
 
25
  global chat_history, followup_count
26
  followup_count = 0
27
  user_detail = user_detail.strip()[:60]
28
  breed_name = custom_breed if breed == "Other" and custom_breed else breed
 
29
 
30
  prompt = f"""Pet: {pet}
31
  Breed: {breed_name}
@@ -33,7 +39,7 @@ Age: {age}, Gender: {gender}, Weight: {weight}
33
  Topic: {topic}"""
34
 
35
  if topic == "Symptom Checker":
36
- prompt += f"\nSymptom: {symptom}"
37
  elif topic == "Nutrition":
38
  prompt += f"\nCondition: {condition}"
39
  prompt += f"\nDetail: {user_detail}\nGive a short and relevant response. If critical, recommend a vet visit."
@@ -109,17 +115,21 @@ with gr.Blocks() as demo:
109
  weight = gr.Textbox(label="Weight (e.g. 10 kg)")
110
 
111
  topic = gr.Dropdown(["Symptom Checker", "Nutrition", "Breed Info"], label="Topic")
112
- symptom = gr.Dropdown(["Vomiting", "Coughing", "Itching", "Diarrhea", "Loss of Appetite", "Limping", "Sneezing"], label="Select Symptom", visible=False)
 
113
  condition = gr.Textbox(label="Condition (optional: slim, weak, etc.)", visible=False)
114
  user_detail = gr.Textbox(label="Problem Detail (max 60 characters)", max_lines=2)
115
 
116
  def toggle_topic_fields(selected_topic):
117
  return (
118
  gr.update(visible=(selected_topic == "Symptom Checker")),
119
- gr.update(visible=(selected_topic == "Nutrition"))
 
 
120
  )
121
 
122
- topic.change(toggle_topic_fields, topic, [symptom, condition])
 
123
 
124
  submit_btn = gr.Button("Get Advice")
125
  output = gr.Textbox(label="AI Advice", lines=8)
@@ -131,7 +141,7 @@ with gr.Blocks() as demo:
131
 
132
  submit_btn.click(
133
  ask_ai,
134
- inputs=[pet, breed, custom_breed, age, gender, weight, topic, symptom, condition, user_detail],
135
  outputs=output
136
  )
137
 
 
14
  "Dog": ["German Shepherd", "Labrador", "Bulldog", "Pomeranian", "Other"]
15
  }
16
 
17
+ symptom_list = ["Vomiting", "Coughing", "Itching", "Diarrhea", "Loss of Appetite", "Limping", "Sneezing", "Other"]
18
+
19
  def update_breeds(pet):
20
  options = breeds.get(pet, [])
21
  return gr.update(choices=options, visible=True, value=None), gr.update(visible=False, value="")
 
23
  def show_custom_breed(breed_selected):
24
  return gr.update(visible=(breed_selected == "Other"), value="")
25
 
26
+ def show_custom_symptom(symptom_selected):
27
+ return gr.update(visible=(symptom_selected == "Other"), value="")
28
+
29
+ def ask_ai(pet, breed, custom_breed, age, gender, weight, topic, symptom, custom_symptom, condition, user_detail):
30
  global chat_history, followup_count
31
  followup_count = 0
32
  user_detail = user_detail.strip()[:60]
33
  breed_name = custom_breed if breed == "Other" and custom_breed else breed
34
+ symptom_name = custom_symptom if symptom == "Other" and custom_symptom else symptom
35
 
36
  prompt = f"""Pet: {pet}
37
  Breed: {breed_name}
 
39
  Topic: {topic}"""
40
 
41
  if topic == "Symptom Checker":
42
+ prompt += f"\nSymptom: {symptom_name}"
43
  elif topic == "Nutrition":
44
  prompt += f"\nCondition: {condition}"
45
  prompt += f"\nDetail: {user_detail}\nGive a short and relevant response. If critical, recommend a vet visit."
 
115
  weight = gr.Textbox(label="Weight (e.g. 10 kg)")
116
 
117
  topic = gr.Dropdown(["Symptom Checker", "Nutrition", "Breed Info"], label="Topic")
118
+ symptom = gr.Dropdown(symptom_list, label="Select Symptom", visible=False)
119
+ custom_symptom = gr.Textbox(label="Enter Symptom", visible=False)
120
  condition = gr.Textbox(label="Condition (optional: slim, weak, etc.)", visible=False)
121
  user_detail = gr.Textbox(label="Problem Detail (max 60 characters)", max_lines=2)
122
 
123
  def toggle_topic_fields(selected_topic):
124
  return (
125
  gr.update(visible=(selected_topic == "Symptom Checker")),
126
+ gr.update(visible=(selected_topic == "Nutrition")),
127
+ gr.update(visible=False),
128
+ gr.update(visible=False)
129
  )
130
 
131
+ topic.change(toggle_topic_fields, topic, [symptom, condition, custom_symptom, custom_breed])
132
+ symptom.change(show_custom_symptom, symptom, custom_symptom)
133
 
134
  submit_btn = gr.Button("Get Advice")
135
  output = gr.Textbox(label="AI Advice", lines=8)
 
141
 
142
  submit_btn.click(
143
  ask_ai,
144
+ inputs=[pet, breed, custom_breed, age, gender, weight, topic, symptom, custom_symptom, condition, user_detail],
145
  outputs=output
146
  )
147