Spaces:
Sleeping
Sleeping
yuvaranianandhan24
commited on
Commit
•
86c6a74
1
Parent(s):
c3896c6
Upload 2 files
Browse files
.env
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
GOOGLE_API_KEY = "AIzaSyBPEcTP4hlkaSTeKQh2jLQhu550H1pwOrI"
|
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import required libraries
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
load_dotenv() # to load all the env variables
|
4 |
+
|
5 |
+
import streamlit as st
|
6 |
+
import os
|
7 |
+
import google.generativeai as genai
|
8 |
+
from PIL import Image
|
9 |
+
import time
|
10 |
+
|
11 |
+
#-------------------------------------------#
|
12 |
+
|
13 |
+
genai.configure(api_key= os.getenv("GOOGLE_API_KEY"))
|
14 |
+
|
15 |
+
# creating function to load gemini pro model
|
16 |
+
|
17 |
+
model = genai.GenerativeModel("gemini-pro-vision")
|
18 |
+
model1 = genai.GenerativeModel("gemini-pro")
|
19 |
+
|
20 |
+
def get_response(input,image):
|
21 |
+
|
22 |
+
start_time = time.time()
|
23 |
+
|
24 |
+
if input != '' and image is not None:
|
25 |
+
response = model.generate_content([input,image])
|
26 |
+
|
27 |
+
|
28 |
+
elif image == None:
|
29 |
+
response = model1.generate_content(input)
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
else:
|
34 |
+
response = model.generate_content(image)
|
35 |
+
#response = response.parts
|
36 |
+
#for part in response:
|
37 |
+
#return (part.text)
|
38 |
+
|
39 |
+
end_time = time.time()
|
40 |
+
response_time = end_time - start_time
|
41 |
+
|
42 |
+
return response.text,response_time
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
# To set up streamlit
|
50 |
+
|
51 |
+
st.set_page_config(page_title="Content Generation LLM Model using Gemini")
|
52 |
+
st.header("Content Generation LLM Model ")
|
53 |
+
|
54 |
+
input = st.text_input("Input Prompt", key="input")
|
55 |
+
|
56 |
+
|
57 |
+
uploaded_file = st.file_uploader("Input Image", type=["jpg", "jpeg", "png"])
|
58 |
+
image=None
|
59 |
+
if uploaded_file is not None:
|
60 |
+
image = Image.open(uploaded_file)
|
61 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
62 |
+
|
63 |
+
submit = st.button("Generate")
|
64 |
+
|
65 |
+
|
66 |
+
## when submit button is clicked,
|
67 |
+
|
68 |
+
if submit:
|
69 |
+
response_text,response_time = get_response(input,image)
|
70 |
+
|
71 |
+
st.subheader("The Generated Content:")
|
72 |
+
st.write(response_text)
|
73 |
+
st.write("Response Time :" ,response_time)
|
74 |
+
|
75 |
+
|