Spaces:
Sleeping

HopePet / README.md
mayadeeb08's picture
Update README.md
469cdd0 verified
|
Raw History Blame Contribute Delete
22.2 kB

A newer version of the Gradio SDK is available: 6.33.0

Upgrade
metadata
title: HopePet
emoji: 🐾
colorFrom: pink
colorTo: blue
sdk: gradio
app_file: app_v2.py
python_version: '3.12'
sdk_version: 6.19.0

🐾 HOPEPET AI

Pet-Care Recommendation & Generation Assistant

Final Project – Intro to Data Science
Authors: Shaked & Maya
Hugging Face Space: https://huggingface.co/spaces/mayadeeb08/HopePet


1. Project Overview

HOPEPET AI is an interactive AI-based pet-care assistant for dog and cat owners.

Many pet owners notice symptoms such as vomiting, appetite loss, hiding, limping, anxiety, low energy, or emergency signs, but they do not always know how serious the situation is. Searching online can also be confusing because the answers are often too general, stressful, or not adapted to the pet’s specific case.

The goal of HOPEPET AI is to give a responsible first-step response. The system helps users understand the possible urgency level, safe first steps, and when they should contact a veterinarian.

Important safety note: HOPEPET AI does not diagnose animals, does not replace a veterinarian, and does not recommend medication or dosages. If a pet has severe symptoms, emergency signs, or worsening condition, the user should contact a veterinarian or emergency clinic immediately.


2. What the App Does

The user enters a free-text question about a dog or cat, for example:

My senior cat stopped eating today and seems very tired. What should I do?

The system then performs the full AI pipeline:

  1. Converts the user input into a text embedding.
  2. Compares the input with synthetic pet-care cases from the dataset.
  3. Retrieves the top 3 most similar cases using cosine similarity.
  4. Uses the retrieved cases as context for the generation model.
  5. Generates a clear, safety-focused response.
  6. Displays urgency level, recommended next step, veterinary warning, and similar cases.

The final output includes:

Output Meaning
AI response A generated first-step explanation for the user
Top 3 similar cases Retrieved synthetic cases most similar to the user input
Problem category The type of issue, such as Health, Emergency, Anxiety, Training, Grooming, or Nutrition
Urgency level Low, Medium, High, or Emergency
Recommended next step What the user should do next
Vet warning Safety-focused veterinary disclaimer

3. Project Structure

The project is divided into two main notebooks.

Notebook Purpose Main Output
01_HOPEPET_Part1_Synthetic_Data_Creation_Assignment_Style.ipynb Creates the synthetic dataset using a prompt-defined design and Python generation rules hopepet_synthetic_dataset.csv
02_HOPEPET_Parts2_3_4_Combined_EDA_Upload_CSV.ipynb Performs EDA, builds embeddings, creates the recommendation system, adds generation, and connects the pipeline to the app EDA results, model comparison, recommendation system, generation pipeline

This structure separates the data creation process from the analysis and model-building process.
Notebook 1 creates the dataset. Notebook 2 uses that dataset for the rest of the project.


4. Dataset Overview

The project uses a synthetic pet-care dataset created specifically for HOPEPET AI.

Dataset Element Description
Dataset type Synthetic text dataset
Number of rows 11,000 synthetic pet-care cases
Original columns 33 columns
Domain Pet care
Supported pets Dogs and cats
Main task Semantic retrieval + recommendation + generation
Main retrieval field retrieval_text
Final application Gradio app on Hugging Face Spaces

Each row represents one fictional dog or cat care case. The dataset does not contain real users, real pets, real veterinary records, or private personal information.

Important fields include:

  • pet_type
  • pet_age_years
  • pet_age_group
  • medical_background
  • recent_change
  • main_symptom
  • secondary_symptoms
  • symptom_duration
  • appetite_status
  • water_intake
  • energy_level
  • pain_signs
  • emergency_signs
  • problem_category
  • urgency_level
  • recommended_next_step
  • triage_reason
  • safe_first_steps
  • vet_warning
  • user_question
  • retrieval_text

The most important field for the recommendation system is retrieval_text. This column combines the structured details of each case into one searchable text field. It is later converted into embeddings and used for semantic similarity search.


5. Synthetic Data Creation

The dataset was created in Notebook 1 using a prompt-defined design and Python code.

The assignment required a model-and-prompt-based dataset creation process. In this project, the prompt was used as a dataset creation contract. It defined the role of the generator, the required fields, the allowed values, the safety rules, and the expected style of the data.

The final dataset was then generated programmatically in Python. This made the process more controlled, reproducible, and easier to validate.

The synthetic data creation process included:

Component Purpose
Prompt contract Defines the role, schema, safety rules, and output expectations
Controlled value lists Prevents inconsistent or random categories
Balanced generation Keeps the dataset more balanced across pet types and important categories
Safety rules Ensures emergency cases receive the correct urgency and recommendation
Edge cases Adds important high-risk examples such as cat cannot urinate or senior cat not eating
Validation checks Confirms the dataset follows the expected structure and logic
CSV export Saves the final dataset for Hugging Face and Notebook 2

Key safety rules used in the data generation:

  • Emergency signs must lead to Emergency urgency.
  • A cat cannot be assigned the Puppy age group.
  • A dog cannot be assigned the Kitten age group.
  • A cat that cannot urinate must be treated as an emergency case.
  • A senior cat that is not eating should be High or Emergency urgency.
  • The dataset does not provide diagnosis, medication advice, or dosage recommendations.

6. Exploratory Data Analysis

The EDA was performed in Notebook 2 after uploading the CSV file created in Notebook 1.

The goal of the EDA was to understand the dataset structure, check data quality, examine distributions, identify patterns, and validate that the synthetic dataset follows the intended safety logic.

The EDA included:

  • Data loading and initial inspection
  • Missing values check
  • Duplicate check
  • Text length analysis
  • Outlier checks
  • Numeric and categorical summaries
  • Pet type distribution
  • Age group distribution
  • Problem category distribution
  • Urgency level distribution
  • Emergency signs vs urgency analysis
  • Recommended next step consistency
  • High-risk pattern analysis
  • PCA visualization of embeddings

7. Data Quality Checks

Before using the dataset for embeddings and generation, the data was checked for quality and consistency.

The checks included missing values, duplicate rows, category consistency, text formatting, and outlier detection. These steps are important because the recommendation and generation pipeline depends on clean and reliable input data.

Age Outlier Check

The age outlier check verifies that pet ages are realistic. This matters because pet age can affect urgency and safety logic. For example, the same symptom may be more concerning for a senior pet than for a young adult pet.

Text Length Outlier Check

The text length analysis checks whether the text fields are reasonable. The retrieval_text field is expected to be longer than user_question because it contains the full structured context of the case. These longer texts are useful for semantic retrieval because they include symptoms, urgency, safe steps, and warnings.

Common Terms in User Questions

The common-terms analysis shows that the user questions include meaningful pet-care language. Frequent terms relate to symptoms, appetite, energy, behavior, hiding, eating, pain, and time. This supports the use of NLP and embeddings because the text contains useful signals for retrieving similar cases.

Unique Values in Categorical Features

The categorical feature analysis confirms that the dataset uses controlled categories. This is important because the project needs both variety and consistency: variety to cover different pet-care situations, and consistency so the recommendation logic can work safely.


8. Main Dataset Distributions

Pet Type Distribution

The dataset is designed to support both dog and cat owners. A balanced or near-balanced pet type distribution helps prevent the system from being biased toward only one type of pet.

Pet Age Group Distribution

The dataset includes different pet life stages, including puppies, kittens, adult pets, and senior pets. This is important because age can change the meaning of a symptom. For example, appetite loss in a senior cat can be more concerning than a mild behavior change in a healthy adult pet.

Problem Category Distribution

The dataset covers several pet-care areas, including Health, Emergency, Behavior, Training, Anxiety, Nutrition, Grooming, and General Care. This variety allows HOPEPET AI to respond to different user needs instead of focusing only on medical symptoms.

Urgency Level Distribution

The dataset includes four urgency levels: Low, Medium, High, and Emergency. This is one of the most important fields in the project because the final app uses urgency to guide the recommended next step.

Medical Background Distribution

Medical background adds important context. A pet with a chronic condition, recent surgery, allergies, or senior age-related issues may require different guidance than a pet with no known medical background.


9. Relationship and Safety Analysis

The most important part of the EDA is not only describing the dataset, but checking whether the synthetic cases follow responsible safety logic.

Problem Category vs Urgency Level

This heatmap shows how urgency levels are distributed across problem categories. Emergency cases should strongly map to Emergency urgency. Training, grooming, behavior, and general care cases are expected to appear more often in Low or Medium urgency. This analysis checks whether the generated labels follow the intended logic.

Age Group and Urgency Level

This visualization shows the relationship between pet age group and urgency level. It helps confirm that the dataset includes different urgency patterns across puppies, kittens, adult pets, and senior pets.

Emergency Signs vs Urgency

This is one of the most important safety checks in the project. Cases with emergency signs should be classified as Emergency. The purpose of this chart is to verify that emergency symptoms do not receive low-risk recommendations.

Recommended Next Step by Urgency

This chart checks whether the recommended next step matches the urgency level.

Urgency Level Expected Recommendation Logic
Low Home monitoring and basic safe care
Medium Close monitoring and contact a vet if symptoms continue or worsen
High Contact a veterinarian soon or same-day vet consultation
Emergency Immediate veterinary care

This validation is critical because the app should never give a weak recommendation for a high-risk case.

High-Risk Rate by Medical Background

This analysis checks whether some medical backgrounds are more associated with High or Emergency urgency. In the current dataset, medical background contributes context, but it is not the only factor that determines urgency. Symptoms, appetite, energy level, and emergency signs are also important.

Recommended Next Step by Problem Category

This graph shows that the app does not use one generic recommendation for every case. The recommended next step changes according to the problem category and urgency level.

High-Risk Rate by Appetite and Energy

This heatmap shows that appetite and energy level are important risk signals. A pet that is not eating and is very tired or weak is usually more concerning than a pet with normal appetite and normal energy.

10. Recommendation with Embeddings

The recommendation component uses text embeddings and cosine similarity.

Each retrieval_text is converted into a numerical vector. The user input is also converted into a vector. The system compares the user vector to the dataset vectors and retrieves the top 3 most similar pet-care cases.

This is useful because the system can find cases that are similar in meaning, not only cases that contain the exact same words.

For example:

My dog is shaking and hiding during fireworks.

can be semantically similar to:

A dog is anxious because of loud noises.

Even if the wording is different, the meaning is related.


11. Embedding Model Comparison

Three Hugging Face SentenceTransformer models were tested:

Model Embedding Dimension Top 3 Hit Rate Top 5 Hit Rate Runtime
sentence-transformers/paraphrase-MiniLM-L3-v2 384 0.750 0.875 16.71 sec
sentence-transformers/all-MiniLM-L6-v2 384 0.750 0.750 67.90 sec
sentence-transformers/all-mpnet-base-v2 768 0.625 0.625 514.33 sec

The metric used here is Hit Rate, not classic classification accuracy.
A Top 3 hit means that the expected problem category appeared somewhere within the first 3 retrieved cases.

Because the evaluation uses a small manual test set and a sample of the dataset, the results should be interpreted as a retrieval sanity check rather than a full benchmark.

Selected Embedding Model

The selected model is:

sentence-transformers/paraphrase-MiniLM-L3-v2

This model achieved the best practical result in the current evaluation. It reached the highest Top 5 Hit Rate and had the shortest runtime among the tested models. It also keeps the embedding size small with 384 dimensions, which makes it practical for a Colab notebook and a Gradio prototype.

Why This Is Not Classic Classification

Although the dataset contains labels such as problem_category and urgency_level, the main task in this project is not classic classification.

In classic classification, the goal is to train a model to predict one label directly. In HOPEPET AI, the goal is different: the system retrieves semantically similar cases using embeddings and cosine similarity. The retrieved cases then provide context for the final generated response.

Therefore, this project is better described as a semantic retrieval and recommendation system combined with text generation.


12. Embedding Space Visualization

PCA by Problem Category

PCA was used to project the high-dimensional embeddings into two dimensions for visualization. This helps inspect whether cases from similar categories show some structure in the embedding space.

The visualization is not used for the actual recommendation calculation. The real retrieval system still uses the full embedding vectors and cosine similarity.


13. Generation Component

HOPEPET AI includes a text generation component using a Hugging Face text-to-text generation model:

google/flan-t5-base

The generation model receives:

  • The user question
  • The top 3 retrieved similar cases
  • Problem category
  • Urgency level
  • Recommended next step
  • Safe first steps
  • Veterinary warning

Then it generates one final user-facing response.

The generated response is designed to be:

  • Clear
  • Helpful
  • Safety-focused
  • Based on retrieved similar cases
  • Not a medical diagnosis
  • Not a replacement for a veterinarian

The generation is grounded in retrieved cases, so the answer is not produced from the language model alone. The system first retrieves relevant cases and then uses them as context.


14. Out-of-Scope Protection

A similarity-based system will always return the nearest cases, even if the user asks something unrelated to pets.

For example:

How do I fix my laptop battery?

This is not a pet-care question. Therefore, the project includes an out-of-scope check using a similarity threshold. If the top similarity score is too low, the system avoids generating a regular pet-care answer and informs the user that the question is outside the scope of HOPEPET AI.

This is important for safety and reliability.


15. Final Gradio App

The final application was deployed as an interactive Gradio app on Hugging Face Spaces.

The app includes:

  • Free-text user input
  • Top 3 similar retrieved cases
  • Generated AI response
  • Urgency level
  • Recommended next step
  • Veterinary warning
  • Safety disclaimer

The app turns the notebook pipeline into a user-facing prototype. Instead of only testing the system inside a notebook, users can enter their own pet-care question and receive a structured response.

The final workflow is:

User input
→ Similarity search
→ Top 3 retrieved cases
→ Safety checks
→ Generation prompt
→ Final response
→ Gradio interface

16. Technologies Used

Technology Role in Project
Python Main programming language
Google Colab Notebook development and experiments
Pandas / NumPy Data handling and analysis
Matplotlib / Plotly Visualizations
Scikit-learn Cosine similarity and PCA
SentenceTransformers Text embeddings
Hugging Face Transformers Text generation
Gradio Interactive app interface
Hugging Face Spaces Deployment

17. Connection to Course Concepts

Course Concept How It Appears in HOPEPET AI
Data Science Process Problem definition, data creation, EDA, model building, evaluation, and deployment
Synthetic Data Programmatic generation of 11,000 fictional pet-care cases
Prompt Engineering Prompt contract used to define dataset structure and safety rules
EDA Missing values, duplicates, outliers, distributions, and relationship analysis
Feature Engineering retrieval_text, high-risk indicators, text length features, and safety-related fields
NLP User questions, retrieval text, word analysis, embeddings, and generation
Recommendation Systems Top 3 similar cases retrieved using embeddings and cosine similarity
Generative AI Final response generated using retrieved cases as context
Deployment Gradio app deployed on Hugging Face Spaces

The project does not focus on regression or classic classification because the main task is semantic retrieval and responsible generation.


18. Limitations and Future Work

This project uses synthetic data. The dataset does not represent real veterinary records or real user cases. The examples were created for educational and development purposes and should not be used as real medical evidence.

HOPEPET AI provides general first-step guidance only. It does not replace a veterinarian and should not be used as a diagnosis tool.

Main limitations:

  • The dataset is synthetic and may not fully represent real pet-care situations.
  • The recommendation quality depends on the coverage of the synthetic dataset.
  • The generation model may produce general responses and should always be constrained by safety rules.
  • The system currently supports only dogs and cats.
  • The evaluation is based on a small manual test set and should be expanded in future work.

Future improvements could include:

  • Adding veterinary-reviewed examples
  • Expanding the dataset with more rare and complex cases
  • Adding more pet types
  • Improving the emergency detection layer
  • Testing the app with expert feedback
  • Adding multilingual support
  • Improving the Gradio interface
  • Adding stronger guardrails before generation

19. Conclusion

HOPEPET AI demonstrates a complete AI/Data Science pipeline for responsible pet-care guidance.

The project includes synthetic data creation, data validation, exploratory data analysis, NLP processing, embedding-based recommendation, retrieval-augmented text generation, and deployment as a Gradio app on Hugging Face Spaces.

The main value of the project is the connection between retrieval and generation. The system retrieves similar pet-care cases from the dataset and then uses them to create a clear, responsible, and safety-focused response for the user.

HOPEPET AI is an educational AI prototype. It is not a replacement for professional veterinary care, but it demonstrates how data science, NLP, recommendation systems, and generative AI can be combined into one working application.