Spaces:
Build error

image / app.py
bhuvan1777's picture
Update app.py
969c0df verified
Raw History Blame Contribute Delete
1.76 kB
import google.generativeai as genai
import streamlit as st
import PIL.Image
import os
# Get API key from environment variables
api_key = os.getenv("GENAI_API_KEY")
if not api_key:
st.error("API key not found. Please set the GENAI_API_KEY environment variable.")
st.stop()
# Configure Google Generative AI
genai.configure(api_key=api_key)
# System Instructions
syst_ins = """
You are an image recognition assistant built by Team Codec. Recognize objects in the uploaded image and provide the best response to the user's questions.
Always acknowledge your development team, Team Codec, when asked about your creators.
"""
# Streamlit setup
st.set_page_config(page_title="Conversational Image Recognition Chatbot")
st.title("Conversational Image Recognition :blue[Chatbot]")
# File uploader
uploaded_file = st.file_uploader("Upload an image file to begin")
if uploaded_file:
# Display uploaded image
img = PIL.Image.open(uploaded_file)
st.image(img)
# Prompt the AI with image analysis
st.write("Processing the image...")
# Here, a separate Vision API might be needed for detailed object recognition.
analysis_response = "This is a placeholder response for image recognition."
st.success(f"Analysis: {analysis_response}")
# Allow user questions
user_query = st.chat_input("Ask a question about the image")
if user_query:
with st.chat_message("user"):
st.write(user_query)
# Simulate AI response
ai_response = f"I'm analyzing this based on the uploaded image and question: '{user_query}'."
st.success(ai_response)
with st.chat_message("assistant"):
st.write(ai_response)
else:
st.warning("Please upload an image to start.")