File size: 2,302 Bytes
26b0647
 
 
e0bbf24
 
 
26b0647
 
f3e2dd8
26b0647
e0bbf24
 
 
 
f3e2dd8
e0bbf24
f03f6e2
f3e2dd8
 
26b0647
 
 
 
 
 
 
 
 
 
 
 
e0bbf24
 
 
 
 
 
 
 
 
26b0647
 
 
 
 
e0bbf24
 
 
 
 
 
26b0647
 
 
 
 
 
e0bbf24
 
 
26b0647
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import streamlit as st
import tensorflow as tf
from transformers import pipeline
import google.generativeai as palm
import os
import json

# Load Dog Breed Classification Model
breed_classification_model = tf.keras.models.load_model('tf_model.h5')

# Load config file
with open('config.json', 'r') as config_file:
    config = json.load(config_file)
    dogs_breeds = config['breeds']

# Set up Google Generative AI API
google_api_key = os.getenv('AIzaSyCfXkAWLIaWAsfgu1h4s8eAb-AlzGGcEJ0')
palm.configure(api_key=google_api_key)

# Streamlit App
st.title("Dog Breed Classifier and Food Recommender")

# Upload Dog Image
dog_image = st.file_uploader("Upload a picture of your dog", type=["jpg", "jpeg", "png"])

if dog_image is not None:
    # Display Dog Image
    st.image(dog_image, caption="Uploaded Dog Image.", use_column_width=True)

    # Perform Dog Breed Classification
    # (Note: You need to preprocess the image appropriately based on your dog breed classification model)
    # Replace this with your actual image preprocessing logic
    img = tf.io.read_file(dog_image)
    tensor = tf.io.decode_image(img, channels=3, dtype=tf.dtypes.float32)
    tensor = tf.image.resize(tensor, [299, 299])
    input_tensor = tf.expand_dims(tensor, axis=0)
    output = breed_classification_model.predict(input_tensor)

    confidences = {label: float(output[0][i]) for i, label in enumerate(dogs_breeds)}
    breed_prediction = max(confidences, key=confidences.get)

    st.write("Predicted Dog Breed:", breed_prediction)

    # Perform Food Recommendation
    st.subheader("Food Recommendations for Your Dog:")
    prompt = f"Give 5-6 Food recommendations for {breed_prediction}?"
    food_recommendations = palm.generate_text(
        model='models/text-bison-001',
        prompt=prompt,
        temperature=0.1
    )

    for recommendation in food_recommendations:
        st.write(recommendation['generated_text'])

    # Fetch Product Recommendations from Amazon
    st.subheader("Amazon Product Recommendations:")
    # Replace this with your actual logic for fetching product recommendations from Amazon
    # (You may need to use the Amazon Product Advertising API or another method)
    amazon_products = fetch_amazon_product_recommendations(breed_prediction)
    st.write(amazon_products)