shikharyashmaurya commited on
Commit
c4561d9
1 Parent(s): 81b0b04

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from PIL import Image
4
+
5
+ import google.generativeai as genai
6
+ secret_key = os.getenv("SECRET_KEY")
7
+ genai.configure(api_key=secret_key)
8
+
9
+ def get_gemini_response(input,image):
10
+ model = genai.GenerativeModel('gemini-pro-vision')
11
+ if input!="":
12
+ input='''You are a prompt generator.You will get an image.
13
+ Your work is to write a prompt such that an image generator model would create most identical picture
14
+ as the image given to you'''
15
+ response = model.generate_content([input,image])
16
+ new_input='''You are a prompt generator.You will get an image.
17
+ Your work is to write a prompt such that an image generator model would create most identical picture
18
+ as the image given to you and the extra feature provide that you mant in image are as follows '''+input
19
+ else:
20
+ response = model.generate_content([new_input,image])
21
+ return response.text
22
+
23
+ st.set_page_config(page_title="Prompt generation from image")
24
+ st.header("Application")
25
+
26
+ input=st.text_input("Any special change in image you want to specify: ",key="input")
27
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
28
+
29
+ image=""
30
+
31
+ if uploaded_file is not None:
32
+ image = Image.open(uploaded_file)
33
+ st.image(image, caption="Uploaded Image.", use_column_width=True)
34
+
35
+ submit=st.button("Generate Prompt")
36
+
37
+ if submit:
38
+ response=get_gemini_response(input,image)
39
+ st.subheader("The Generated Prompt is")
40
+ st.write(response)