GeminiBot / app.py
imcalleddevansh's picture
Update app.py
52748fc
import streamlit as st
from PIL import Image
import google.generativeai as genai
import os
genai.configure(api_key=os.getenv("geminikey"))
def get_gemini_qa_response(question):
model = genai.GenerativeModel('gemini-pro')
chat = model.start_chat(history=[])
response = chat.send_message(question, stream=True)
return response
# Function to get Gemini Image response
def get_gemini_image_response(input_prompt, image):
model = genai.GenerativeModel('gemini-pro-vision')
if input_prompt != "":
response = model.generate_content([input_prompt, image])
else:
response = model.generate_content(image)
return response.text
# Set page configuration
st.set_page_config(page_title="Gemini Bot")
# Header
st.title("Gemini Bot")
# Tabs for options
option = st.sidebar.radio("Select an option:", ("Q&A bot", "Image bot"))
# Content based on the selected option
if option == "Q&A bot":
st.subheader("Q&A Option")
input_question = st.text_input("Input: ", key="input_qa")
submit_button_qa = st.button("Ask the question")
if submit_button_qa:
response_qa = get_gemini_qa_response(input_question)
st.subheader("The Response is")
for chunk in response_qa:
st.write(chunk.text)
st.write("_" * 80)
elif option == "Image bot":
st.subheader("Image Option")
input_prompt = st.text_input("Input Prompt: ", key="input_img")
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
image = ""
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image.", use_column_width=True)
submit_button_img = st.button("Tell me about the image")
if submit_button_img:
response_img = get_gemini_image_response(input_prompt, image)
st.subheader("The Response is")
st.write(response_img)