Spaces:
No application file
No application file
imcalleddevansh
commited on
Commit
•
017eaa2
1
Parent(s):
6e61651
Upload 2 files
Browse files- finalapp.py +63 -0
- requirement.txt +3 -0
finalapp.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import google.generativeai as genai
|
4 |
+
##from dotenv import load_dotenv
|
5 |
+
import os
|
6 |
+
##load_dotenv()
|
7 |
+
|
8 |
+
# Configure Gemini API key
|
9 |
+
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
10 |
+
|
11 |
+
# Function to get Gemini Q&A response
|
12 |
+
def get_gemini_qa_response(question):
|
13 |
+
model = genai.GenerativeModel('gemini-pro')
|
14 |
+
chat = model.start_chat(history=[])
|
15 |
+
response = chat.send_message(question, stream=True)
|
16 |
+
return response
|
17 |
+
|
18 |
+
# Function to get Gemini Image response
|
19 |
+
def get_gemini_image_response(input_prompt, image):
|
20 |
+
model = genai.GenerativeModel('gemini-pro-vision')
|
21 |
+
if input_prompt != "":
|
22 |
+
response = model.generate_content([input_prompt, image])
|
23 |
+
else:
|
24 |
+
response = model.generate_content(image)
|
25 |
+
return response.text
|
26 |
+
|
27 |
+
# Set page configuration
|
28 |
+
st.set_page_config(page_title="Gemini Bot")
|
29 |
+
|
30 |
+
# Header
|
31 |
+
st.title("Gemini Bot")
|
32 |
+
|
33 |
+
# Tabs for options
|
34 |
+
option = st.sidebar.radio("Select an option:", ("Q&A bot", "Image bot"))
|
35 |
+
|
36 |
+
# Content based on the selected option
|
37 |
+
if option == "Q&A bot":
|
38 |
+
st.subheader("Q&A Option")
|
39 |
+
input_question = st.text_input("Input: ", key="input_qa")
|
40 |
+
submit_button_qa = st.button("Ask the question")
|
41 |
+
|
42 |
+
if submit_button_qa:
|
43 |
+
response_qa = get_gemini_qa_response(input_question)
|
44 |
+
st.subheader("The Response is")
|
45 |
+
for chunk in response_qa:
|
46 |
+
st.write(chunk.text)
|
47 |
+
st.write("_" * 80)
|
48 |
+
|
49 |
+
elif option == "Image bot":
|
50 |
+
st.subheader("Image Option")
|
51 |
+
input_prompt = st.text_input("Input Prompt: ", key="input_img")
|
52 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
53 |
+
image = ""
|
54 |
+
if uploaded_file is not None:
|
55 |
+
image = Image.open(uploaded_file)
|
56 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
57 |
+
|
58 |
+
submit_button_img = st.button("Tell me about the image")
|
59 |
+
|
60 |
+
if submit_button_img:
|
61 |
+
response_img = get_gemini_image_response(input_prompt, image)
|
62 |
+
st.subheader("The Response is")
|
63 |
+
st.write(response_img)
|
requirement.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
google-generativeai
|
3 |
+
python-dotenv
|