Darknightcoder/Text_To_image_Generation
4
1import streamlit as st2import requests3import tempfile4import numpy as np5 6# Set page config7st.set_page_config(page_title='Image Generation', page_icon=':pizza:', layout='wide')8 9st.title('Pizza Image Generation')10 11# Initialize session state for storing user inputs12if 'dynamic_prompt' not in st.session_state:13 st.session_state['dynamic_prompt'] = ""14if 'image_data' not in st.session_state:15 st.session_state['image_data'] = None16 17# Define pizza options18pizza_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 25pizza_sizes = ["Small", "Medium", "Large", "Extra Large"]26 27toppings_options = ["Arugula", "Bacon", "Basil", "Broccoli", "Cheese", "Chicken", "Corn", 28 "Ham", "Mushroom", "Olives", "Onion", "Pepperoni", "Peppers", 29 "Pineapple", "Tomatoes"]30 31bg_color_options = ['White', 'Black', 'Light Blue', 'Light Green', 'Light Yellow', 'Light Pink']32 33orientation_options = ["Top View", "Side View", "Lateral View"]34 35# UI Components for Pizza Preferences36with st.form(key='prompt_form'):37 # Pizza selection38 selected_pizza = st.selectbox("Choose a Pizza Type", pizza_names)39 selected_size = st.selectbox("Choose Pizza Size", pizza_sizes)40 41 # Toppings selection42 selected_toppings = st.multiselect("Choose Toppings", toppings_options, default=["Mushroom", "Tomatoes", "Onion"])43 44 # Additional customization45 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 prompt52if 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...57with st.form(key='image_form'):58 generate_image_button = st.form_submit_button(label='Generate Image')59 60if generate_image_button and st.session_state['dynamic_prompt']:61 # Generate the image using your custom model62 # Assuming 'my_custom_model_generate_image' is a function that returns the image data63 st.session_state['image_data'] = (st.session_state['dynamic_prompt'])64 65 # Display the generated image if available66 if st.session_state['image_data'] is not None:67 st.image(st.session_state['image_data'], caption="Generated Image", use_column_width=True)68 