Darknightcoder
commited on
Commit
•
a1322b1
1
Parent(s):
acb8c94
Update app.py
Browse files
app.py
CHANGED
@@ -1,74 +1,70 @@
|
|
1 |
import streamlit as st
|
2 |
-
import requests
|
3 |
import tempfile
|
4 |
|
5 |
# Set page config
|
6 |
-
st.set_page_config(page_title='Image Generation', page_icon=':
|
7 |
|
8 |
st.title('Image Generation')
|
9 |
|
10 |
# Initialize session state
|
11 |
if 'dynamic_prompt' not in st.session_state:
|
12 |
st.session_state['dynamic_prompt'] = ""
|
13 |
-
if 'image_generated' not in st.session_state:
|
14 |
-
st.session_state['image_generated'] = False
|
15 |
if 'image_url' not in st.session_state:
|
16 |
st.session_state['image_url'] = ""
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Main content
|
19 |
-
with st.form(key='
|
20 |
# Image generation input
|
21 |
size = st.selectbox('Select size of the images', ('256x256', '512x512', '1024x1024'))
|
22 |
-
num_images = st.selectbox('Select Number of Images to be Generated', ('1', '2', '3', '4', '5'))
|
23 |
|
24 |
# Pizza order input
|
25 |
-
pizza_names = ["Crispy Chicken", "Chicken Pesto", ...] #
|
26 |
name = st.selectbox("Name of Pizza", pizza_names)
|
27 |
size_pizza = st.selectbox("Size of Pizza", ["Small", "Medium", "Large", "Extra Large"])
|
28 |
-
toppings_options = ["Arugula", "Bacon", ...] # truncated for brevity
|
29 |
toppings = st.multiselect("Toppings", toppings_options, default=["Mushroom", "Tomatoes", "Onion"])
|
30 |
prompt = st.text_input(label='Enter additional Descriptions ')
|
31 |
-
bg_color_options = ['White', 'Black',
|
32 |
bg_color = st.selectbox('Select Background Color', bg_color_options)
|
33 |
orientation = ["Top View", "Side View", "Lateral View"]
|
34 |
orientation_checkbox = st.multiselect("Orientation", orientation, default=["Top View"])
|
35 |
|
36 |
generate_prompt_button = st.form_submit_button(label='Generate Prompt')
|
37 |
|
38 |
-
#
|
39 |
if generate_prompt_button:
|
40 |
-
st.session_state['dynamic_prompt'] = f"Imagine you are a marketer who wants to post an image on social media for a {size_pizza} {name} Pizza with following toppings
|
41 |
-
st.write(st.session_state['dynamic_prompt'])
|
42 |
-
st.session_state['image_url'] = "url_of_your_generated_image" # Here, integrate with your custom model
|
43 |
-
st.session_state['image_generated'] = True
|
44 |
|
45 |
-
# Display the button to generate the image
|
46 |
-
|
47 |
-
|
48 |
-
generate_image_button = st.form_submit_button(label='Generate Image')
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
response = requests.get(st.session_state['image_url'])
|
59 |
-
with open(tmp_file.name, "wb") as f:
|
60 |
-
f.write(response.content) # Saving the image data
|
61 |
-
st.download_button(
|
62 |
-
label="Download image",
|
63 |
-
data=tmp_file,
|
64 |
-
file_name="generated_image.png",
|
65 |
-
mime="image/png"
|
66 |
-
)
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import requests
|
3 |
import tempfile
|
4 |
|
5 |
# Set page config
|
6 |
+
st.set_page_config(page_title='Image Generation', page_icon=':camera:', layout='wide')
|
7 |
|
8 |
st.title('Image Generation')
|
9 |
|
10 |
# Initialize session state
|
11 |
if 'dynamic_prompt' not in st.session_state:
|
12 |
st.session_state['dynamic_prompt'] = ""
|
|
|
|
|
13 |
if 'image_url' not in st.session_state:
|
14 |
st.session_state['image_url'] = ""
|
15 |
+
if 'image_generated' not in st.session_state:
|
16 |
+
st.session_state['image_generated'] = False
|
17 |
+
|
18 |
+
# Define your toppings options
|
19 |
+
toppings_options = ["Mushroom", "Tomatoes", "Onion", "Arugula", "Bacon", "Basil", "Broccoli", "Cheese", "Chicken", "Corn", "Ham", "Olives", "Pepperoni", "Peppers", "Pineapple"]
|
20 |
|
21 |
# Main content
|
22 |
+
with st.form(key='prompt_form'):
|
23 |
# Image generation input
|
24 |
size = st.selectbox('Select size of the images', ('256x256', '512x512', '1024x1024'))
|
25 |
+
num_images = st.selectbox('Select Number of Images to be Generated', ('1', '2', '3', '4', '5'))
|
26 |
|
27 |
# Pizza order input
|
28 |
+
pizza_names = ["Crispy Chicken", "Chicken Pesto", "..."] # Add the rest of the pizza names
|
29 |
name = st.selectbox("Name of Pizza", pizza_names)
|
30 |
size_pizza = st.selectbox("Size of Pizza", ["Small", "Medium", "Large", "Extra Large"])
|
|
|
31 |
toppings = st.multiselect("Toppings", toppings_options, default=["Mushroom", "Tomatoes", "Onion"])
|
32 |
prompt = st.text_input(label='Enter additional Descriptions ')
|
33 |
+
bg_color_options = ['White', 'Black', 'Light Blue', 'Light Green', 'Light Yellow', 'Light Pink']
|
34 |
bg_color = st.selectbox('Select Background Color', bg_color_options)
|
35 |
orientation = ["Top View", "Side View", "Lateral View"]
|
36 |
orientation_checkbox = st.multiselect("Orientation", orientation, default=["Top View"])
|
37 |
|
38 |
generate_prompt_button = st.form_submit_button(label='Generate Prompt')
|
39 |
|
40 |
+
# Generate the dynamic prompt
|
41 |
if generate_prompt_button:
|
42 |
+
st.session_state['dynamic_prompt'] = f"Imagine you are a marketer who wants to post an image on social media for a {size_pizza} {name} Pizza with the following toppings: {', '.join(toppings)}. I want to generate an image for the given description in {', '.join(orientation_checkbox)} with a background color of {bg_color}."
|
43 |
+
st.write("Prompt:", st.session_state['dynamic_prompt'])
|
|
|
|
|
44 |
|
45 |
+
# Display the button to generate the image
|
46 |
+
with st.form(key='image_form'):
|
47 |
+
generate_image_button = st.form_submit_button(label='Generate Image')
|
|
|
48 |
|
49 |
+
if generate_image_button and st.session_state['dynamic_prompt']:
|
50 |
+
# Here, integrate with your custom model to generate the image
|
51 |
+
# For now, using a placeholder URL
|
52 |
+
st.session_state['image_url'] = "url_of_your_generated_image"
|
53 |
+
st.session_state['image_generated'] = True
|
54 |
|
55 |
+
# Display the generated image
|
56 |
+
if st.session_state['image_url']:
|
57 |
+
st.image(st.session_state['image_url'], caption="Generated Image", use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
# Download button for the generated image
|
60 |
+
if st.session_state['image_generated']:
|
61 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_file:
|
62 |
+
response = requests.get(st.session_state['image_url'])
|
63 |
+
with open(tmp_file.name, "wb") as f:
|
64 |
+
f.write(response.content) # Save the image data
|
65 |
+
st.download_button(
|
66 |
+
label="Download Image",
|
67 |
+
data=tmp_file,
|
68 |
+
file_name="generated_image.png",
|
69 |
+
mime="image/png"
|
70 |
+
)
|