chburhan64 commited on
Commit
e8bdfe6
·
verified ·
1 Parent(s): 69a9feb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -2
app.py CHANGED
@@ -1,3 +1,106 @@
1
- import streamlit as st
 
2
 
3
- st.title("Hello from Animal AI Assistant")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
 
4
+ API_KEY = "2d19ae2e41864ddf81690cc806ffe941" # Replace with your AIMLAPI API key
5
+
6
+ def call_aimlapi(messages):
7
+ url = "https://api.aimlapi.com/v1/chat/completions"
8
+ headers = {
9
+ "Authorization": f"Bearer {API_KEY}",
10
+ "Content-Type": "application/json"
11
+ }
12
+ data = {
13
+ "model": "gpt-4o-mini",
14
+ "messages": messages
15
+ }
16
+ response = requests.post(url, headers=headers, json=data)
17
+ if response.status_code == 200:
18
+ return response.json()["choices"][0]["message"]["content"]
19
+ else:
20
+ return f"Error: {response.status_code} - {response.text}"
21
+
22
+ def get_solution(animal_type, species, age, gender, weight, info_type, issue_desc, symptoms):
23
+ # Build a detailed prompt with symptom info (if health selected)
24
+ symptom_text = ""
25
+ if info_type.lower() == "health" and symptoms:
26
+ symptom_text = f"\nSymptoms reported: {', '.join(symptoms)}"
27
+
28
+ user_message = f"""
29
+ Animal type: {animal_type}
30
+ Species: {species}
31
+ Age: {age}
32
+ Gender: {gender}
33
+ Weight: {weight}
34
+ Information requested: {info_type}
35
+ Description: {issue_desc}
36
+ {symptom_text}
37
+
38
+ Please provide a detailed, clear, and helpful answer based on these details.
39
+ Include:
40
+ - Emergency warnings if any critical symptoms are present.
41
+ - Nutrition tips if relevant.
42
+ - Breed-specific information if applicable.
43
+ - Safe natural remedies and medicines (with a disclaimer to consult a vet).
44
+ - And any other useful advice.
45
+
46
+ Make the response friendly and easy to understand.
47
+ """
48
+
49
+ messages = [
50
+ {"role": "system", "content": "You are a knowledgeable and helpful veterinary assistant."},
51
+ {"role": "user", "content": user_message}
52
+ ]
53
+
54
+ answer = call_aimlapi(messages)
55
+ return answer
56
+
57
+ # Common symptoms for health issues (can be expanded)
58
+ COMMON_SYMPTOMS = [
59
+ "Coughing", "Vomiting", "Diarrhea", "Lethargy", "Loss of appetite",
60
+ "Limping", "Excessive scratching", "Swelling", "Discharge from eyes or nose",
61
+ "Difficulty breathing", "Seizures", "Excessive thirst", "Weight loss"
62
+ ]
63
+
64
+ with gr.Blocks() as demo:
65
+ gr.Markdown("# 🐾 Pet & Animal Healthcare AI Assistant")
66
+
67
+ with gr.Row():
68
+ animal_type = gr.Dropdown(choices=["Pet", "Domestic", "Wild"], label="Animal Type", value="Pet", interactive=True)
69
+ species = gr.Textbox(label="Species (e.g., dog, cat, cow, lion)", placeholder="Enter species", interactive=True)
70
+
71
+ with gr.Row():
72
+ age = gr.Number(label="Age (years)", value=1, interactive=True, precision=1)
73
+ gender = gr.Dropdown(choices=["Male", "Female", "Unknown"], label="Gender", value="Unknown", interactive=True)
74
+ weight = gr.Number(label="Weight (kg)", value=1, interactive=True, precision=1)
75
+
76
+ info_type = gr.Dropdown(
77
+ choices=["Health", "Nutrition", "Breed", "Other"],
78
+ label="Information Requested",
79
+ value="Health",
80
+ interactive=True
81
+ )
82
+
83
+ issue_desc = gr.Textbox(label="Describe your issue or question (1-2 lines)", lines=3, placeholder="Enter description here...")
84
+
85
+ symptoms = gr.CheckboxGroup(
86
+ choices=COMMON_SYMPTOMS,
87
+ label="Select symptoms (only if Health info requested)",
88
+ visible=True
89
+ )
90
+
91
+ def toggle_symptoms_visibility(info_type):
92
+ return gr.update(visible=(info_type == "Health"))
93
+
94
+ info_type.change(fn=toggle_symptoms_visibility, inputs=info_type, outputs=symptoms)
95
+
96
+ submit_btn = gr.Button("Get Solution")
97
+ output = gr.Textbox(label="AI Solution", lines=20)
98
+
99
+ submit_btn.click(
100
+ fn=get_solution,
101
+ inputs=[animal_type, species, age, gender, weight, info_type, issue_desc, symptoms],
102
+ outputs=output
103
+ )
104
+
105
+ if __name__ == "__main__":
106
+ demo.launch()