Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
API_KEY = os.getenv("
|
| 6 |
API_URL = "https://api.aimlapi.com/v1/chat/completions"
|
| 7 |
SYSTEM_PROMPT = (
|
| 8 |
"You are a highly knowledgeable and friendly veterinary assistant AI. "
|
|
@@ -39,10 +39,26 @@ def handle_symptom_other(symptom):
|
|
| 39 |
def handle_info_other(info):
|
| 40 |
return gr.update(visible=(info == "Other"), value="")
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
def ask_ai(pet, breed, other_breed, age, gender, weight, topic, symptom, other_symptom, condition, info_topic, other_info, user_detail):
|
| 43 |
global chat_history, followup_count
|
| 44 |
followup_count = 0
|
| 45 |
|
|
|
|
|
|
|
|
|
|
| 46 |
pet = pet.strip()
|
| 47 |
final_breed = other_breed.strip() if breed == "Other" else breed
|
| 48 |
final_symptom = other_symptom.strip() if symptom == "Other" else symptom
|
|
@@ -68,7 +84,7 @@ def ask_ai(pet, breed, other_breed, age, gender, weight, topic, symptom, other_s
|
|
| 68 |
"recommended treatments and home care, expected recovery timeline, preventive measures, and when to seek a vet."
|
| 69 |
)
|
| 70 |
elif topic == "Nutrition":
|
| 71 |
-
prompt_parts.append(f"Condition: {condition
|
| 72 |
prompt_parts.append(
|
| 73 |
"Provide a comprehensive nutrition guide for this breed/condition: best foods available locally (Pakistan), benefits of each food, "
|
| 74 |
"recommended feeding quantity and frequency, and tips for maintaining optimal health."
|
|
@@ -167,7 +183,7 @@ with gr.Blocks() as demo:
|
|
| 167 |
symptom.change(handle_symptom_other, symptom, other_symptom)
|
| 168 |
|
| 169 |
with gr.Column(visible=False) as nutrition_section:
|
| 170 |
-
condition = gr.Textbox(label="🩺 Condition (
|
| 171 |
|
| 172 |
with gr.Column(visible=False) as breed_info_section:
|
| 173 |
info_topic = gr.Dropdown(breed_info_topics, label="ℹ️ Select Info Type")
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
API_KEY = os.getenv("AIMLAPI_API_KEY") or "your_aimlapi_key_here"
|
| 6 |
API_URL = "https://api.aimlapi.com/v1/chat/completions"
|
| 7 |
SYSTEM_PROMPT = (
|
| 8 |
"You are a highly knowledgeable and friendly veterinary assistant AI. "
|
|
|
|
| 39 |
def handle_info_other(info):
|
| 40 |
return gr.update(visible=(info == "Other"), value="")
|
| 41 |
|
| 42 |
+
def validate_inputs(pet, breed, other_breed, age, gender, weight, topic, symptom, other_symptom, condition, info_topic, other_info):
|
| 43 |
+
if not pet or not age.strip() or not gender or not weight.strip() or not topic:
|
| 44 |
+
return False
|
| 45 |
+
if topic == "Symptom Checker" and (not symptom or (symptom == "Other" and not other_symptom.strip())):
|
| 46 |
+
return False
|
| 47 |
+
if topic == "Nutrition" and not condition.strip():
|
| 48 |
+
return False
|
| 49 |
+
if topic == "Breed Info" and (not info_topic or (info_topic == "Other" and not other_info.strip())):
|
| 50 |
+
return False
|
| 51 |
+
if breed == "Other" and not other_breed.strip():
|
| 52 |
+
return False
|
| 53 |
+
return True
|
| 54 |
+
|
| 55 |
def ask_ai(pet, breed, other_breed, age, gender, weight, topic, symptom, other_symptom, condition, info_topic, other_info, user_detail):
|
| 56 |
global chat_history, followup_count
|
| 57 |
followup_count = 0
|
| 58 |
|
| 59 |
+
if not validate_inputs(pet, breed, other_breed, age, gender, weight, topic, symptom, other_symptom, condition, info_topic, other_info):
|
| 60 |
+
return "⚠️ Please complete all required fields before getting advice."
|
| 61 |
+
|
| 62 |
pet = pet.strip()
|
| 63 |
final_breed = other_breed.strip() if breed == "Other" else breed
|
| 64 |
final_symptom = other_symptom.strip() if symptom == "Other" else symptom
|
|
|
|
| 84 |
"recommended treatments and home care, expected recovery timeline, preventive measures, and when to seek a vet."
|
| 85 |
)
|
| 86 |
elif topic == "Nutrition":
|
| 87 |
+
prompt_parts.append(f"Condition: {condition}")
|
| 88 |
prompt_parts.append(
|
| 89 |
"Provide a comprehensive nutrition guide for this breed/condition: best foods available locally (Pakistan), benefits of each food, "
|
| 90 |
"recommended feeding quantity and frequency, and tips for maintaining optimal health."
|
|
|
|
| 183 |
symptom.change(handle_symptom_other, symptom, other_symptom)
|
| 184 |
|
| 185 |
with gr.Column(visible=False) as nutrition_section:
|
| 186 |
+
condition = gr.Textbox(label="🩺 Condition (Required)")
|
| 187 |
|
| 188 |
with gr.Column(visible=False) as breed_info_section:
|
| 189 |
info_topic = gr.Dropdown(breed_info_topics, label="ℹ️ Select Info Type")
|