imcalleddevansh commited on
Commit
1a8567c
1 Parent(s): 88f6884

Create app.py

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