chattest / app.py
ProPerNounpYK's picture
Update app.py
537f1cc verified
import openai
import streamlit as st
# Initialize OpenAI API Key (use Hugging Face Secrets to store this securely)
openai.api_key = st.secrets["openai_api_key"]
# Outfit suggestions database
outfit_database = {
"casual": {
"red jacket": ["white t-shirt", "blue jeans", "white sneakers", "black crossbody bag"],
"denim skirt": ["striped blouse", "tan sandals", "straw hat", "neutral tote bag"]
},
"formal": {
"red jacket": ["black turtleneck", "black trousers", "pointed heels", "gold necklace"],
"denim skirt": ["silk blouse", "nude pumps", "pearl earrings", "clutch bag"]
},
"streetwear": {
"red jacket": ["graphic tee", "cargo pants", "high-top sneakers", "beanie"],
"denim skirt": ["oversized hoodie", "combat boots", "chunky necklace", "fanny pack"]
},
# Add more clothing items and styles here
}
# Function to generate outfit advice
def generate_outfit_advice(piece, color, style):
key = f"{color} {piece}" if f"{color} {piece}" in outfit_database.get(style, {}) else piece
suggestions = outfit_database.get(style, {}).get(key, None)
if not suggestions:
return "Sorry, I couldn't find an outfit for your request. Try another combination!"
top, bottom, footwear, accessory = suggestions
advice = (f"Here’s how you can style your {color} {piece} for a {style} look:\n"
f"- Top: {top}\n- Bottom: {bottom}\n- Footwear: {footwear}\n- Accessory: {accessory}")
return advice
# Function to generate image prompt for OpenAI's DALL-E
def generate_image_prompt(piece, color, style):
return f"A {style} outfit featuring a {color} {piece} styled with complementary clothing items and accessories. Modern, fashionable, and cohesive."
# Function to create outfit image using OpenAI's DALL-E (updated for version 1.0.0)
def create_outfit_image(prompt):
response = openai.Image.create(
model="dall-e", # Use the 'dall-e' model for image generation
prompt=prompt,
n=1,
size="1024x1024"
)
return response['data'][0]['url']
# Streamlit UI
def main():
st.title("AI Fashion Outfit Generator")
st.write("Enter the details of your clothing piece, color, and style to get personalized fashion advice and a visual representation.")
# Form to collect user inputs
with st.form(key='outfit_form'):
piece = st.text_input("Enter the clothing piece (e.g., 'jacket', 'skirt')").lower()
color = st.text_input("Enter the color (e.g., 'red', 'black')").lower()
style = st.selectbox("Select style", ["casual", "formal", "streetwear", "boho"])
submit_button = st.form_submit_button(label='Generate Outfit')
if submit_button:
if piece and color:
# Generate advice and image based on user input
advice = generate_outfit_advice(piece, color, style)
image_prompt = generate_image_prompt(piece, color, style)
if "Sorry" not in advice:
# Display the outfit advice and image
st.write(advice)
image_url = create_outfit_image(image_prompt)
st.image(image_url, caption="Generated Outfit", use_column_width=True)
else:
st.error(advice)
else:
st.warning("Please enter both a clothing piece and a color.")
if __name__ == '__main__':
main()