Spaces:
Runtime error
Runtime error
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) | |