msn-enginenova21 commited on
Commit
8f9e87a
1 Parent(s): 5db4515

Upload 3 files

Browse files
Files changed (3) hide show
  1. .env +1 -0
  2. app.py +68 -0
  3. requirements.txt +4 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API="AIzaSyD6fIFPMHFEvi4bFHIyFg_mq82qhcWUYsY"
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import streamlit as st
3
+ import os
4
+ import google.generativeai as genai
5
+ import streamlit_analytics
6
+ from PIL import Image
7
+
8
+ load_dotenv()
9
+ GOOGLE_API_KEY = os.getenv("GOOGLE_API")
10
+ genai.configure(api_key=GOOGLE_API_KEY)
11
+ model = genai.GenerativeModel('gemini-pro')
12
+ model_vision = genai.GenerativeModel('gemini-pro-vision')
13
+
14
+
15
+ def gemini_response(question):
16
+ try:
17
+ response1 = model.generate_content(question)
18
+ return response1.text
19
+ except Exception as e:
20
+ raise e
21
+
22
+
23
+ def gemini_response_vision(input_texts, image):
24
+ try:
25
+ if input_texts != "":
26
+ response2 = model_vision.generate_content([input_texts, image])
27
+ else:
28
+ response2 = model_vision.generate_content(image)
29
+
30
+ return response2.text
31
+
32
+ except Exception as e:
33
+ raise e
34
+
35
+
36
+ # streamlit_analytics.start_tracking()
37
+ tab1, tab2 = st.tabs(["TAB_1:Gemini LLM App Q & A:sunglasses:", "TAB_2:Gemini-Pro-Vision Image To Text:rocket:"])
38
+
39
+ with tab1:
40
+ st.title('Generative Question And Answer :blue[Gemini LLM App] :sunglasses:')
41
+ input_1 = st.text_input("Ask Question:")
42
+
43
+ submit1 = st.button("Generate Response")
44
+ if submit1:
45
+ if input_1 is not None:
46
+ st.write('Your Query Response')
47
+ response = gemini_response(input_1)
48
+ st.write(response)
49
+ else:
50
+ st.write("Enter The Text")
51
+
52
+ with tab2:
53
+ st.title('Generative Image Description :blue[Gemini-Pro-Vision LLM App] :sunglasses:')
54
+
55
+ uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
56
+ input_2 = st.text_input("Text for Image: Ask question related to uploaded image")
57
+
58
+ if uploaded_image is not None:
59
+ img = Image.open(uploaded_image)
60
+ st.image(img, caption="upload images", use_column_width=True)
61
+
62
+ submit2 = st.button("Generate Text from Image ")
63
+
64
+ if submit2:
65
+ st.subheader("Response:")
66
+ res = gemini_response_vision(input_texts=input_2, image=img)
67
+ st.write(res)
68
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ Streamlit~=1.31.0
2
+ google-generativeai
3
+ python-dotenv~=0.21.0
4
+ pillow~=10.2.0