laxminarasimha6 commited on
Commit
6f89923
1 Parent(s): 7111163

Upload 5 files

Browse files
Files changed (5) hide show
  1. .env +1 -0
  2. app.py +48 -0
  3. chat.py +48 -0
  4. requirements.txt +3 -0
  5. vision.py +47 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY = "AIzaSyDUgfjwgH9lMEfxe_dQQMN-MH4syGlmifM"
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+
3
+ load_dotenv() # take environment variables from .env.
4
+
5
+ import streamlit as st
6
+ import os
7
+ import pathlib
8
+ import textwrap
9
+
10
+ import google.generativeai as genai
11
+
12
+ from IPython.display import display
13
+ from IPython.display import Markdown
14
+
15
+
16
+ def to_markdown(text):
17
+ text = text.replace('•', ' *')
18
+ return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
19
+
20
+
21
+ os.getenv("GOOGLE_API_KEY")
22
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
23
+
24
+
25
+ ## Function to load OpenAI model and get respones
26
+
27
+ def get_gemini_response(question):
28
+ model = genai.GenerativeModel('gemini-pro')
29
+ response = model.generate_content(question)
30
+ return response.text
31
+
32
+
33
+ ##initialize our streamlit app
34
+
35
+ st.set_page_config(page_title="Q&A Demo")
36
+
37
+ st.header("Sujatha Pro")
38
+
39
+ input = st.text_input("Input: ", key="input")
40
+
41
+ submit = st.button("Ask the question")
42
+
43
+ ## If ask button is clicked
44
+
45
+ if submit:
46
+ response = get_gemini_response(input)
47
+ st.subheader("The Response is")
48
+ st.write(response)
chat.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+
3
+ load_dotenv() # take environment variables from .env.
4
+
5
+ import streamlit as st
6
+ import os
7
+ import pathlib
8
+ import textwrap
9
+
10
+ import google.generativeai as genai
11
+
12
+ from IPython.display import display
13
+ from IPython.display import Markdown
14
+
15
+ os.getenv("GOOGLE_API_KEY")
16
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
17
+
18
+ ## Function to load OpenAI model and get respones
19
+ model = genai.GenerativeModel('gemini-pro')
20
+ chat = model.start_chat(history=[])
21
+
22
+
23
+ def get_gemini_response(question):
24
+ response = chat.send_message(question, stream=True)
25
+ return response
26
+
27
+
28
+ ##initialize our streamlit app
29
+
30
+ st.set_page_config(page_title="Q&A Demo")
31
+
32
+ st.header("Gemini Application")
33
+
34
+ input = st.text_input("Input: ", key="input")
35
+
36
+ submit = st.button("Ask the question")
37
+
38
+ ## If ask button is clicked
39
+
40
+ if submit:
41
+
42
+ response = get_gemini_response(input)
43
+ st.subheader("The Response is")
44
+ for chunk in response:
45
+ print(st.write(chunk.text))
46
+ print("_" * 80)
47
+
48
+ st.write(chat.history)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
vision.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+
3
+ load_dotenv() # take environment variables from .env.
4
+
5
+ import streamlit as st
6
+ import os
7
+ import pathlib
8
+ import textwrap
9
+ from PIL import Image
10
+
11
+ import google.generativeai as genai
12
+
13
+ os.getenv("GOOGLE_API_KEY")
14
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
15
+
16
+
17
+ ## Function to load OpenAI model and get respones
18
+
19
+ def get_gemini_response(input, image):
20
+ model = genai.GenerativeModel('gemini-pro-vision')
21
+ if input != "":
22
+ response = model.generate_content([input, image])
23
+ else:
24
+ response = model.generate_content(image)
25
+ return response.text
26
+
27
+
28
+ ##initialize our streamlit app
29
+
30
+ st.set_page_config(page_title="Gemini Image Demo")
31
+
32
+ st.header("Gemini Application")
33
+ input = st.text_input("Input Prompt: ", key="input")
34
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
35
+ image = ""
36
+ if uploaded_file is not None:
37
+ image = Image.open(uploaded_file)
38
+ st.image(image, caption="Uploaded Image.", use_column_width=True)
39
+
40
+ submit = st.button("Tell me about the image")
41
+
42
+ ## If ask button is clicked
43
+
44
+ if submit:
45
+ response = get_gemini_response(input, image)
46
+ st.subheader("The Response is")
47
+ st.write(response)