Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
|
11 |
# Function to get response from Gemini model
|
12 |
def get_gemini_response(input_prompt, image_data, genre, length, language, mood):
|
13 |
model = genai.GenerativeModel('gemini-1.5-flash')
|
|
|
14 |
# If both image and text are provided
|
15 |
if image_data and input_prompt:
|
16 |
full_prompt = f"""
|
@@ -73,23 +74,34 @@ st.markdown("### Upload your image or provide a prompt to create a Vision around
|
|
73 |
col1, col2 = st.columns([2, 3]) # 2 + 3 = 5 parts total
|
74 |
|
75 |
with col1:
|
76 |
-
|
77 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
78 |
-
|
79 |
-
genre = st.selectbox("Select Genre:", ["story", "shayari", "sher", "poem", "quote"])
|
80 |
-
length = st.selectbox("Select Length:", ["short", "long"])
|
81 |
-
language = st.selectbox("Select Language:", ["English", "Spanish"])
|
82 |
-
mood = st.selectbox("Select Mood:", ["emotional", "sad", "happy", "horror", "comedy", "romantic"])
|
83 |
|
84 |
-
#
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
86 |
|
|
|
|
|
|
|
|
|
87 |
if uploaded_file is not None:
|
88 |
image = Image.open(uploaded_file)
|
89 |
col1.image(image, caption="Uploaded Image", use_column_width=True)
|
90 |
|
91 |
# Handle submit action
|
92 |
if submit:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
if uploaded_file or input_prompt:
|
94 |
try:
|
95 |
image_data = input_image_setup(uploaded_file)
|
|
|
11 |
# Function to get response from Gemini model
|
12 |
def get_gemini_response(input_prompt, image_data, genre, length, language, mood):
|
13 |
model = genai.GenerativeModel('gemini-1.5-flash')
|
14 |
+
|
15 |
# If both image and text are provided
|
16 |
if image_data and input_prompt:
|
17 |
full_prompt = f"""
|
|
|
74 |
col1, col2 = st.columns([2, 3]) # 2 + 3 = 5 parts total
|
75 |
|
76 |
with col1:
|
77 |
+
# File uploader for image upload
|
78 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
+
# Expander for additional options, closed by default
|
81 |
+
with st.expander("Additional Options", expanded=False): # Changed to expanded=False
|
82 |
+
input_prompt = st.text_input("Input Prompt (optional):", placeholder="Enter your prompt here...")
|
83 |
+
genre = st.selectbox("Select Genre:", ["story", "shayari", "sher", "poem", "quote"])
|
84 |
+
length = st.selectbox("Select Length:", ["short", "long"])
|
85 |
+
language = st.selectbox("Select Language:", ["English", "Spanish"])
|
86 |
+
mood = st.selectbox("Select Mood:", ["emotional", "sad", "happy", "horror", "comedy", "romantic"])
|
87 |
|
88 |
+
# Generate button with color
|
89 |
+
submit = st.button("Generate", key="generate_button", style="color: white; background-color: green; width: 100%;")
|
90 |
+
|
91 |
+
# Display uploaded image
|
92 |
if uploaded_file is not None:
|
93 |
image = Image.open(uploaded_file)
|
94 |
col1.image(image, caption="Uploaded Image", use_column_width=True)
|
95 |
|
96 |
# Handle submit action
|
97 |
if submit:
|
98 |
+
# Use data from input fields whether or not the expander is open
|
99 |
+
input_prompt = st.session_state.get('input_prompt', None)
|
100 |
+
genre = st.session_state.get('genre', None)
|
101 |
+
length = st.session_state.get('length', None)
|
102 |
+
language = st.session_state.get('language', None)
|
103 |
+
mood = st.session_state.get('mood', None)
|
104 |
+
|
105 |
if uploaded_file or input_prompt:
|
106 |
try:
|
107 |
image_data = input_image_setup(uploaded_file)
|