Spaces:
Sleeping
Sleeping
File size: 3,420 Bytes
c1b5e4e 78e41d5 c1b5e4e 537f1cc c1b5e4e 537f1cc c1b5e4e d9a0196 78e41d5 c1b5e4e 7a6824f c1b5e4e 78e41d5 c1b5e4e 537f1cc c1b5e4e 537f1cc c1b5e4e 537f1cc c1b5e4e 78e41d5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
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()
|