Darknightcoder
commited on
Commit
•
4a39ad4
1
Parent(s):
2be961a
Update app.py
Browse files
app.py
CHANGED
@@ -1,78 +1,67 @@
|
|
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 '
|
14 |
-
st.session_state['
|
15 |
-
if 'image_generated' not in st.session_state:
|
16 |
-
st.session_state['image_generated'] = False
|
17 |
|
18 |
-
# Define
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
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 |
-
#
|
41 |
if generate_prompt_button:
|
42 |
-
st.session_state['dynamic_prompt'] = f"
|
43 |
st.write("Prompt:", st.session_state['dynamic_prompt'])
|
44 |
|
45 |
-
#
|
46 |
with st.form(key='image_form'):
|
47 |
generate_image_button = st.form_submit_button(label='Generate Image')
|
48 |
|
49 |
-
|
50 |
-
|
51 |
if generate_image_button and st.session_state['dynamic_prompt']:
|
52 |
-
#
|
53 |
-
# Assuming 'my_custom_model_generate_image' is a function that returns the image
|
54 |
-
st.session_state['
|
55 |
-
st.session_state['image_generated'] = st.session_state['image_url'] is not None
|
56 |
-
|
57 |
-
# Display the generated image if the URL is valid
|
58 |
-
if st.session_state['image_url']:
|
59 |
-
try:
|
60 |
-
st.image(st.session_state['image_url'], caption="Generated Image", use_column_width=True)
|
61 |
-
except Exception as e:
|
62 |
-
st.error(f"Failed to load image from URL: {e}")
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
|
67 |
-
#
|
68 |
-
if st.session_state['
|
69 |
-
|
70 |
-
response = requests.get(st.session_state['image_url'])
|
71 |
-
with open(tmp_file.name, "wb") as f:
|
72 |
-
f.write(response.content) # Save the image data
|
73 |
-
st.download_button(
|
74 |
-
label="Download Image",
|
75 |
-
data=tmp_file,
|
76 |
-
file_name="generated_image.png",
|
77 |
-
mime="image/png"
|
78 |
-
)
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
import tempfile
|
4 |
+
import numpy as np
|
5 |
|
6 |
# Set page config
|
7 |
+
st.set_page_config(page_title='Image Generation', page_icon=':pizza:', layout='wide')
|
8 |
|
9 |
+
st.title('Pizza Image Generation')
|
10 |
|
11 |
+
# Initialize session state for storing user inputs
|
12 |
if 'dynamic_prompt' not in st.session_state:
|
13 |
st.session_state['dynamic_prompt'] = ""
|
14 |
+
if 'image_data' not in st.session_state:
|
15 |
+
st.session_state['image_data'] = None
|
|
|
|
|
16 |
|
17 |
+
# Define pizza options
|
18 |
+
pizza_names = ["Crispy Chicken", "Chicken Pesto", "Deluxe Pepperoni", "Truffle Mushroom",
|
19 |
+
"Ultimate Cheese", "Spicy Veggie Ranch", "Classic Chicken Ranch",
|
20 |
+
"BBQ Chicken Ranch", "Spicy Chicken Ranch", "Very Veggie",
|
21 |
+
"Super Supreme", "Classic Pepperoni", "Margherita", "Cheeky Chicken",
|
22 |
+
"Chicken Super Supreme", "Chicken BBQ Supreme", "Chicken Fajita",
|
23 |
+
"Chicken Shawerma", "Other"]
|
24 |
|
25 |
+
pizza_sizes = ["Small", "Medium", "Large", "Extra Large"]
|
26 |
+
|
27 |
+
toppings_options = ["Arugula", "Bacon", "Basil", "Broccoli", "Cheese", "Chicken", "Corn",
|
28 |
+
"Ham", "Mushroom", "Olives", "Onion", "Pepperoni", "Peppers",
|
29 |
+
"Pineapple", "Tomatoes"]
|
30 |
+
|
31 |
+
bg_color_options = ['White', 'Black', 'Light Blue', 'Light Green', 'Light Yellow', 'Light Pink']
|
32 |
+
|
33 |
+
orientation_options = ["Top View", "Side View", "Lateral View"]
|
34 |
|
35 |
+
# UI Components for Pizza Preferences
|
36 |
+
with st.form(key='prompt_form'):
|
37 |
+
# Pizza selection
|
38 |
+
selected_pizza = st.selectbox("Choose a Pizza Type", pizza_names)
|
39 |
+
selected_size = st.selectbox("Choose Pizza Size", pizza_sizes)
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
+
# Toppings selection
|
42 |
+
selected_toppings = st.multiselect("Choose Toppings", toppings_options, default=["Mushroom", "Tomatoes", "Onion"])
|
43 |
+
|
44 |
+
# Additional customization
|
45 |
+
additional_description = st.text_input("Enter additional descriptions (optional)")
|
46 |
+
background_color = st.selectbox("Choose Background Color", bg_color_options)
|
47 |
+
orientation = st.multiselect("Select Orientation", orientation_options, default=["Top View"])
|
48 |
+
|
49 |
generate_prompt_button = st.form_submit_button(label='Generate Prompt')
|
50 |
|
51 |
+
# Processing user input to generate dynamic prompt
|
52 |
if generate_prompt_button:
|
53 |
+
st.session_state['dynamic_prompt'] = f"A {selected_size} {selected_pizza} Pizza with {', '.join(selected_toppings)}. Additional description: {additional_description}. Background color: {background_color}. Orientation: {', '.join(orientation)}."
|
54 |
st.write("Prompt:", st.session_state['dynamic_prompt'])
|
55 |
|
56 |
+
# Rest of your code for image generation and display...
|
57 |
with st.form(key='image_form'):
|
58 |
generate_image_button = st.form_submit_button(label='Generate Image')
|
59 |
|
|
|
|
|
60 |
if generate_image_button and st.session_state['dynamic_prompt']:
|
61 |
+
# Generate the image using your custom model
|
62 |
+
# Assuming 'my_custom_model_generate_image' is a function that returns the image data
|
63 |
+
st.session_state['image_data'] = my_custom_model_generate_image(st.session_state['dynamic_prompt'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
# Display the generated image if available
|
66 |
+
if st.session_state['image_data'] is not None:
|
67 |
+
st.image(st.session_state['image_data'], caption="Generated Image", use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|