File size: 1,911 Bytes
1a8567c
 
 
52748fc
 
 
1a8567c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)