Darknightcoder commited on
Commit
4a39ad4
1 Parent(s): 2be961a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -55
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=':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
-
50
-
51
  if generate_image_button and st.session_state['dynamic_prompt']:
52
- # Integrate with your custom model to generate the image
53
- # Assuming 'my_custom_model_generate_image' is a function that returns the image URL
54
- st.session_state['image_url'] = my_custom_model_generate_image(st.session_state['dynamic_prompt'])
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
- # Download button for the generated image
68
- if st.session_state['image_generated']:
69
- with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as tmp_file:
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)