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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: mit
|
| 5 |
+
library_name: transformers
|
| 6 |
+
tags:
|
| 7 |
+
- pet-care
|
| 8 |
+
- ai-assistant
|
| 9 |
+
- recommendation-system
|
| 10 |
+
- embeddings
|
| 11 |
+
- text-generation
|
| 12 |
+
- synthetic-data
|
| 13 |
+
- gradio
|
| 14 |
+
- huggingface
|
| 15 |
+
datasets:
|
| 16 |
+
- synthetic-pet-care-dataset
|
| 17 |
+
metrics:
|
| 18 |
+
- top_3_retrieval_hit_rate
|
| 19 |
+
- top_5_retrieval_hit_rate
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
# 🐾 HOPEPET AI: Pet Care Recommendation & Generation Assistant
|
| 23 |
+
### Final AI Application Project | Reichman University
|
| 24 |
+
**Authors:** Shaked & Maya
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## Project Overview
|
| 29 |
+
|
| 30 |
+
HOPEPET is an AI-powered pet-care assistant for dog and cat owners. The app helps users describe a pet-related problem and receive responsible first-step guidance based on similar synthetic pet-care cases.
|
| 31 |
+
|
| 32 |
+
The motivation behind the project is simple: pet owners often do not know how serious a situation is. A symptom that looks mild in one pet may be more serious in another pet depending on age, medical background, appetite, energy level, pain signs, emergency signs, and symptom duration.
|
| 33 |
+
|
| 34 |
+
For example, a dog shaking during fireworks may be related to anxiety, while a senior cat that suddenly stops eating may require veterinary attention. HOPEPET does not diagnose animals. Instead, it retrieves similar cases and generates a clear, safety-focused first response.
|
| 35 |
+
|
| 36 |
+
> **Safety note:** HOPEPET provides general guidance only and does not replace professional veterinary advice. If a pet has difficulty breathing, seizures, bleeding, possible poisoning, repeated vomiting, severe weakness, collapse, or cannot stand, the user should contact a veterinarian or emergency clinic immediately.
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## Application Logic
|
| 41 |
+
|
| 42 |
+
The app combines retrieval and generation. First, it finds similar cases using embeddings. Then, it uses a Hugging Face generative model to create one final response for the user.
|
| 43 |
+
|
| 44 |
+
```text
|
| 45 |
+
User question
|
| 46 |
+
→ Text embedding
|
| 47 |
+
→ Similarity search
|
| 48 |
+
→ Top 3 similar pet-care cases
|
| 49 |
+
→ Hugging Face generation model
|
| 50 |
+
→ Final AI response
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
The final output includes the problem category, estimated urgency level, recommended next step, safe first steps, veterinary warning, similar cases from the dataset, and one generated answer.
|
| 54 |
+
|
| 55 |
+
---
|
| 56 |
+
|
| 57 |
+
## Dataset Overview
|
| 58 |
+
|
| 59 |
+
The project uses a synthetic pet-care dataset with **10,000 examples**. Each row represents one possible pet-care case for a dog or cat.
|
| 60 |
+
|
| 61 |
+
| Dataset Element | Description |
|
| 62 |
+
|---|---|
|
| 63 |
+
| Dataset type | Synthetic text dataset |
|
| 64 |
+
| Number of examples | 10,000 |
|
| 65 |
+
| Domain | Pet care |
|
| 66 |
+
| Supported pets | Dogs and cats |
|
| 67 |
+
| Main AI task | Recommendation + Generation |
|
| 68 |
+
| Main retrieval field | `retrieval_text` |
|
| 69 |
+
| Final output | User-facing pet-care guidance |
|
| 70 |
+
|
| 71 |
+
The dataset includes structured fields such as pet type, age group, medical background, symptoms, urgency level, safe first steps, recommended next step, and veterinary warning.
|
| 72 |
+
|
| 73 |
+
A key column is `retrieval_text`. This column combines the most important details of each case into one searchable text field, which is later converted into embeddings.
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## Synthetic Data Generation
|
| 78 |
+
|
| 79 |
+
The dataset was generated synthetically to support a full AI application. The generation process was not based on one simple prompt. It used several prompting techniques to create a structured, diverse, and safety-aware dataset.
|
| 80 |
+
|
| 81 |
+
| Prompting Technique | Purpose |
|
| 82 |
+
|---|---|
|
| 83 |
+
| Role-based prompting | The model acted as a dataset creator for a responsible pet-care assistant. |
|
| 84 |
+
| Constraint-based prompting | The data followed a strict schema with required columns and controlled categories. |
|
| 85 |
+
| Variation prompting | The dataset includes different pets, symptoms, ages, urgency levels, and medical backgrounds. |
|
| 86 |
+
| Safety-focused prompting | The cases include emergency signs, vet warnings, and safe next steps. |
|
| 87 |
+
| Retrieval-focused prompting | The `retrieval_text` column was created for embedding-based search. |
|
| 88 |
+
|
| 89 |
+
This structure makes the dataset useful for both recommendation and generation.
|
| 90 |
+
|
| 91 |
+
---
|
| 92 |
+
|
| 93 |
+
## Data Validation and Cleaning
|
| 94 |
+
|
| 95 |
+
Before building the AI system, the dataset was validated to make sure it was clean and consistent. The checks included dataset shape, column names, data types, missing values, duplicate rows, unique values, text length fields, and categorical consistency.
|
| 96 |
+
|
| 97 |
+

|
| 98 |
+
|
| 99 |
+

|
| 100 |
+
|
| 101 |
+
The final dataset contains no missing values and no duplicate rows after cleaning. This matters because both recommendation and generation depend on clean, consistent examples.
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## Descriptive Statistics
|
| 106 |
+
|
| 107 |
+
The descriptive statistics section helped verify that the dataset values are reasonable before moving to embeddings and generation.
|
| 108 |
+
|
| 109 |
+
The main numeric fields are `pet_age_years`, `user_question_word_count`, `retrieval_text_word_count`, and `detailed_advice_word_count`. The main categorical fields are `pet_type`, `pet_age_group`, `problem_category`, `urgency_level`, `medical_background`, and `recommended_next_step`.
|
| 110 |
+
|
| 111 |
+

|
| 112 |
+
|
| 113 |
+

|
| 114 |
+
|
| 115 |
+
The numeric analysis showed that pet ages are within a realistic range for dogs and cats. The text-length fields also showed an important pattern: `retrieval_text` is longer than `user_question`, because it contains richer context for semantic search.
|
| 116 |
+
|
| 117 |
+

|
| 118 |
+
|
| 119 |
+
The categorical summary shows that the dataset combines controlled categories with meaningful variety. This is useful because the app needs structure, but it also needs enough diversity to retrieve relevant cases.
|
| 120 |
+
|
| 121 |
+
---
|
| 122 |
+
|
| 123 |
+
## Exploratory Data Analysis
|
| 124 |
+
|
| 125 |
+
The EDA helped understand what the dataset contains and whether it behaves in a logical way.
|
| 126 |
+
|
| 127 |
+
### Pet Type Distribution
|
| 128 |
+
|
| 129 |
+

|
| 130 |
+
|
| 131 |
+
The dataset is almost balanced between dogs and cats. This is important because HOPEPET should support both dog owners and cat owners, without being strongly biased toward only one pet type.
|
| 132 |
+
|
| 133 |
+
### Pet Age Groups
|
| 134 |
+
|
| 135 |
+

|
| 136 |
+
|
| 137 |
+
The dataset includes puppies, kittens, adult pets, and senior pets. Age matters because the same symptom can have a different urgency depending on the pet’s life stage.
|
| 138 |
+
|
| 139 |
+
### Problem Categories
|
| 140 |
+
|
| 141 |
+

|
| 142 |
+
|
| 143 |
+
The dataset covers several pet-care areas, including health, emergency, anxiety, behavior, training, nutrition, and grooming. This variety makes the app more useful because users may come with many different types of questions.
|
| 144 |
+
|
| 145 |
+
### Urgency Levels
|
| 146 |
+
|
| 147 |
+

|
| 148 |
+
|
| 149 |
+
The dataset includes Low, Medium, High, and Emergency urgency levels. This allows the system to provide different levels of guidance depending on the seriousness of the case.
|
| 150 |
+
|
| 151 |
+
### Medical Background
|
| 152 |
+
|
| 153 |
+

|
| 154 |
+
|
| 155 |
+
Medical background is important because the same symptom may require different guidance for a healthy pet and for a pet with an existing condition.
|
| 156 |
+
|
| 157 |
+
---
|
| 158 |
+
|
| 159 |
+
## Safety and Consistency Analysis
|
| 160 |
+
|
| 161 |
+
This part checks whether the synthetic dataset follows responsible logic between symptoms, urgency levels, and recommended actions.
|
| 162 |
+
|
| 163 |
+
### Problem Category vs. Urgency Level
|
| 164 |
+
|
| 165 |
+

|
| 166 |
+
|
| 167 |
+
This heatmap shows how urgency levels are distributed within each problem category. Emergency cases are strongly connected to Emergency urgency. Health-related cases tend to have higher urgency. Training, grooming, and nutrition cases are more often connected to Low or Medium urgency. This supports the internal logic of the dataset.
|
| 168 |
+
|
| 169 |
+
### Age Group and Urgency
|
| 170 |
+
|
| 171 |
+

|
| 172 |
+
|
| 173 |
+
This bubble chart shows that all age groups are represented across urgency levels. This matters because the recommendation system should work for puppies, kittens, adult pets, and senior pets.
|
| 174 |
+
|
| 175 |
+
### Emergency Signs and Urgency
|
| 176 |
+
|
| 177 |
+

|
| 178 |
+
|
| 179 |
+
This is one of the most important safety checks. Cases with emergency signs are connected to Emergency urgency. This supports the idea that HOPEPET should treat emergency signs as high-risk and recommend immediate veterinary attention.
|
| 180 |
+
|
| 181 |
+
### Recommended Next Step by Urgency
|
| 182 |
+
|
| 183 |
+

|
| 184 |
+
|
| 185 |
+
This heatmap checks whether the recommended next step matches the urgency level.
|
| 186 |
+
|
| 187 |
+
| Urgency Level | Expected Recommendation |
|
| 188 |
+
|---|---|
|
| 189 |
+
| Low | Monitor at home |
|
| 190 |
+
| Medium | Monitor closely |
|
| 191 |
+
| High | Contact a veterinarian soon |
|
| 192 |
+
| Emergency | Contact an emergency veterinary clinic immediately |
|
| 193 |
+
|
| 194 |
+
The graph confirms that the dataset provides consistent and safety-focused next steps.
|
| 195 |
+
|
| 196 |
+
### High-Risk Cases by Medical Background
|
| 197 |
+
|
| 198 |
+

|
| 199 |
+
|
| 200 |
+
This graph shows the percentage of High or Emergency cases within each medical background. It highlights why medical history is important: the same symptom may require more careful attention for pets with existing conditions.
|
| 201 |
+
|
| 202 |
+
### Recommended Next Step by Problem Category
|
| 203 |
+
|
| 204 |
+

|
| 205 |
+
|
| 206 |
+
This graph shows that different problem categories lead to different recommended actions. The system does not give one generic answer for every case. It adjusts the next step according to the type and seriousness of the problem.
|
| 207 |
+
|
| 208 |
+
### Appetite, Energy, and Risk
|
| 209 |
+
|
| 210 |
+

|
| 211 |
+
|
| 212 |
+
This graph looks at the relationship between appetite, energy level, and high-risk cases. A pet that is not eating and has low energy is usually more concerning than a pet with normal appetite and normal energy.
|
| 213 |
+
|
| 214 |
+
### Recent Change and Risk
|
| 215 |
+
|
| 216 |
+

|
| 217 |
+
|
| 218 |
+
This graph checks whether recent changes are connected to a higher or lower risk rate. Recent changes can be important context because a sudden change in behavior, appetite, or environment may affect the urgency of the situation.
|
| 219 |
+
|
| 220 |
+
---
|
| 221 |
+
|
| 222 |
+
## Recommendation with Embeddings
|
| 223 |
+
|
| 224 |
+
The recommendation component uses text embeddings. Each `retrieval_text` is converted into a vector. The user input is also converted into a vector. Then the system compares the user vector to all dataset vectors using cosine similarity and returns the top 3 most similar cases.
|
| 225 |
+
|
| 226 |
+
This is useful because the system can find cases that are similar in meaning, not only cases that use the exact same words.
|
| 227 |
+
|
| 228 |
+
```text
|
| 229 |
+
"My dog is shaking and hiding during fireworks"
|
| 230 |
+
```
|
| 231 |
+
|
| 232 |
+
can be semantically similar to:
|
| 233 |
+
|
| 234 |
+
```text
|
| 235 |
+
"Dog is anxious because of loud noises"
|
| 236 |
+
```
|
| 237 |
+
|
| 238 |
+
even if the wording is different.
|
| 239 |
+
|
| 240 |
+
### Tested Embedding Models
|
| 241 |
+
|
| 242 |
+
I tested three Hugging Face embedding models:
|
| 243 |
+
|
| 244 |
+
| Model | Embedding Dimension | Runtime Seconds | Top 3 Hit Rate | Top 5 Hit Rate |
|
| 245 |
+
|---|---:|---:|---:|---:|
|
| 246 |
+
| all-MiniLM-L6-v2 | 384 | 100.03 | 1.00 | 1.00 |
|
| 247 |
+
| paraphrase-MiniLM-L3-v2 | 384 | 25.77 | 0.83 | 1.00 |
|
| 248 |
+
| all-mpnet-base-v2 | 768 | 610.24 | 1.00 | 1.00 |
|
| 249 |
+
|
| 250 |
+
The score is a retrieval hit rate, not regular classification accuracy. A Top 3 hit means that the expected problem category appeared somewhere within the top 3 retrieved cases.
|
| 251 |
+
|
| 252 |
+
### Selected Model
|
| 253 |
+
|
| 254 |
+
The selected embedding model is:
|
| 255 |
+
|
| 256 |
+
`sentence-transformers/all-MiniLM-L6-v2`
|
| 257 |
+
|
| 258 |
+
This model was selected because it provided the best balance between retrieval quality, runtime, embedding size, and practical usability for the final Gradio app.
|
| 259 |
+
|
| 260 |
+
Although `all-mpnet-base-v2` also performed well, it was much slower and produced larger embeddings. Although `paraphrase-MiniLM-L3-v2` was faster, it had lower Top 3 retrieval performance.
|
| 261 |
+
|
| 262 |
+
The final embedding matrix shape is:
|
| 263 |
+
|
| 264 |
+
```text
|
| 265 |
+
(10000, 384)
|
| 266 |
+
```
|
| 267 |
+
|
| 268 |
+
This means that all 10,000 pet-care cases were converted into 384-dimensional vectors.
|
| 269 |
+
|
| 270 |
+
---
|
| 271 |
+
|
| 272 |
+
## Generation Component
|
| 273 |
+
|
| 274 |
+
HOPEPET also includes a Generative AI component using a Hugging Face model.
|
| 275 |
+
|
| 276 |
+
The generation model receives the user question, the top 3 retrieved similar cases, problem category, urgency level, triage reason, safe first steps, recommended next step, and veterinary warning. Then it generates one final user-facing response.
|
| 277 |
+
|
| 278 |
+
The response is designed to be clear, helpful, responsible, safety-focused, based on retrieved cases, and not a medical diagnosis.
|
| 279 |
+
|
| 280 |
+
### Example User Flow
|
| 281 |
+
|
| 282 |
+
User input:
|
| 283 |
+
|
| 284 |
+
```text
|
| 285 |
+
My senior cat stopped eating today and seems very tired.
|
| 286 |
+
```
|
| 287 |
+
|
| 288 |
+
Expected system behavior:
|
| 289 |
+
|
| 290 |
+
- Retrieve similar cases related to cats, appetite loss, tiredness, health or nutrition concerns, and higher urgency.
|
| 291 |
+
- Generate a response that explains the main concern.
|
| 292 |
+
- Include the estimated urgency level.
|
| 293 |
+
- Recommend the next step.
|
| 294 |
+
- Add a veterinary warning and safety disclaimer.
|
| 295 |
+
|
| 296 |
+
---
|
| 297 |
+
|
| 298 |
+
## Final Gradio App
|
| 299 |
+
|
| 300 |
+
The final application is built with Gradio. The app displays the user input, top 3 similar cases, problem category, urgency level, recommended next step, generated AI response, veterinary warning, and safety disclaimer.
|
| 301 |
+
|
| 302 |
+
### Quick Starter Examples
|
| 303 |
+
|
| 304 |
+
```text
|
| 305 |
+
My dog is shaking and hiding during fireworks.
|
| 306 |
+
```
|
| 307 |
+
|
| 308 |
+
```text
|
| 309 |
+
My senior cat stopped eating today and seems very tired.
|
| 310 |
+
```
|
| 311 |
+
|
| 312 |
+
```text
|
| 313 |
+
My puppy keeps biting my hands during playtime.
|
| 314 |
+
```
|
| 315 |
+
|
| 316 |
+
These examples test three different situations: anxiety, health concern, and training.
|
| 317 |
+
|
| 318 |
+
---
|
| 319 |
+
|
| 320 |
+
## Technologies Used
|
| 321 |
+
|
| 322 |
+
- Python
|
| 323 |
+
- Pandas
|
| 324 |
+
- NumPy
|
| 325 |
+
- Matplotlib
|
| 326 |
+
- Scikit-learn
|
| 327 |
+
- Sentence Transformers
|
| 328 |
+
- Hugging Face Transformers
|
| 329 |
+
- Hugging Face Models
|
| 330 |
+
- Gradio
|
| 331 |
+
- Google Colab
|
| 332 |
+
|
| 333 |
+
---
|
| 334 |
+
|
| 335 |
+
## Limitations and Future Improvements
|
| 336 |
+
|
| 337 |
+
This project uses a synthetic dataset, so it does not replace real veterinary data. The app does not diagnose medical conditions and does not replace a veterinarian. The generated response depends on the quality of the retrieved similar cases, and real-world deployment would require expert veterinary review and stronger safety validation.
|
| 338 |
+
|
| 339 |
+
Future improvements could include real anonymized veterinary guidance data, more pet types, multilingual support, stronger emergency detection, structured user forms, user feedback, and a larger embedding evaluation set.
|
| 340 |
+
|
| 341 |
+
---
|
| 342 |
+
|
| 343 |
+
## Conclusion
|
| 344 |
+
|
| 345 |
+
HOPEPET demonstrates a complete AI application pipeline for responsible pet-care guidance.
|
| 346 |
+
|
| 347 |
+
The project includes synthetic data generation, data validation, EDA, embedding-based recommendation, Hugging Face text generation, and a final user-facing Gradio app.
|
| 348 |
+
|
| 349 |
+
The main value of the project is the connection between retrieval and generation. The recommendation system retrieves similar cases from the dataset, and the generation component turns those cases into a clear, responsible, and safety-focused response for the user.
|