Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import openai
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
openai.api_key = "your_openai_api_key_here"
|
| 5 |
|
| 6 |
# Outfit suggestions database
|
|
@@ -16,26 +17,25 @@ outfit_database = {
|
|
| 16 |
# Add more clothing items and styles here
|
| 17 |
}
|
| 18 |
|
|
|
|
| 19 |
def generate_outfit_advice(piece, color, style):
|
| 20 |
-
# Find the clothing piece in the database
|
| 21 |
key = f"{color} {piece}" if f"{color} {piece}" in outfit_database.get(style, {}) else piece
|
| 22 |
suggestions = outfit_database.get(style, {}).get(key, None)
|
| 23 |
|
| 24 |
if not suggestions:
|
| 25 |
return "Sorry, I couldn't find an outfit for your request. Try another combination!"
|
| 26 |
|
| 27 |
-
# Generate outfit advice
|
| 28 |
top, bottom, footwear, accessory = suggestions
|
| 29 |
advice = (f"Here’s how you can style your {color} {piece} for a {style} look:\n"
|
| 30 |
f"- Top: {top}\n- Bottom: {bottom}\n- Footwear: {footwear}\n- Accessory: {accessory}")
|
| 31 |
return advice
|
| 32 |
|
|
|
|
| 33 |
def generate_image_prompt(piece, color, style):
|
| 34 |
-
# Create a text prompt for image generation
|
| 35 |
return f"A {style} outfit featuring a {color} {piece} styled with complementary clothing items and accessories. Modern, fashionable, and cohesive."
|
| 36 |
|
|
|
|
| 37 |
def create_outfit_image(prompt):
|
| 38 |
-
# Generate an image using OpenAI's DALL-E API
|
| 39 |
response = openai.Image.create(
|
| 40 |
prompt=prompt,
|
| 41 |
n=1,
|
|
@@ -43,18 +43,34 @@ def create_outfit_image(prompt):
|
|
| 43 |
)
|
| 44 |
return response["data"][0]["url"]
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
#
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import openai
|
| 2 |
+
import streamlit as st
|
| 3 |
|
| 4 |
+
# Set your OpenAI API key
|
| 5 |
openai.api_key = "your_openai_api_key_here"
|
| 6 |
|
| 7 |
# Outfit suggestions database
|
|
|
|
| 17 |
# Add more clothing items and styles here
|
| 18 |
}
|
| 19 |
|
| 20 |
+
# Function to generate outfit advice
|
| 21 |
def generate_outfit_advice(piece, color, style):
|
|
|
|
| 22 |
key = f"{color} {piece}" if f"{color} {piece}" in outfit_database.get(style, {}) else piece
|
| 23 |
suggestions = outfit_database.get(style, {}).get(key, None)
|
| 24 |
|
| 25 |
if not suggestions:
|
| 26 |
return "Sorry, I couldn't find an outfit for your request. Try another combination!"
|
| 27 |
|
|
|
|
| 28 |
top, bottom, footwear, accessory = suggestions
|
| 29 |
advice = (f"Here’s how you can style your {color} {piece} for a {style} look:\n"
|
| 30 |
f"- Top: {top}\n- Bottom: {bottom}\n- Footwear: {footwear}\n- Accessory: {accessory}")
|
| 31 |
return advice
|
| 32 |
|
| 33 |
+
# Function to generate image prompt for OpenAI's DALL-E
|
| 34 |
def generate_image_prompt(piece, color, style):
|
|
|
|
| 35 |
return f"A {style} outfit featuring a {color} {piece} styled with complementary clothing items and accessories. Modern, fashionable, and cohesive."
|
| 36 |
|
| 37 |
+
# Function to create outfit image using OpenAI's DALL-E
|
| 38 |
def create_outfit_image(prompt):
|
|
|
|
| 39 |
response = openai.Image.create(
|
| 40 |
prompt=prompt,
|
| 41 |
n=1,
|
|
|
|
| 43 |
)
|
| 44 |
return response["data"][0]["url"]
|
| 45 |
|
| 46 |
+
# Streamlit UI
|
| 47 |
+
def main():
|
| 48 |
+
st.title("AI Fashion Outfit Generator")
|
| 49 |
+
st.write("Enter the details of your clothing piece, color, and style to get personalized fashion advice and a visual representation.")
|
| 50 |
+
|
| 51 |
+
# Form to collect user inputs
|
| 52 |
+
with st.form(key='outfit_form'):
|
| 53 |
+
piece = st.text_input("Enter the clothing piece (e.g., 'jacket', 'skirt')").lower()
|
| 54 |
+
color = st.text_input("Enter the color (e.g., 'red', 'black')").lower()
|
| 55 |
+
style = st.selectbox("Select style", ["casual", "formal", "streetwear", "boho"])
|
| 56 |
+
|
| 57 |
+
submit_button = st.form_submit_button(label='Generate Outfit')
|
| 58 |
+
|
| 59 |
+
if submit_button:
|
| 60 |
+
if piece and color:
|
| 61 |
+
# Generate advice and image based on user input
|
| 62 |
+
advice = generate_outfit_advice(piece, color, style)
|
| 63 |
+
image_prompt = generate_image_prompt(piece, color, style)
|
| 64 |
+
|
| 65 |
+
if "Sorry" not in advice:
|
| 66 |
+
# Display the outfit advice and image
|
| 67 |
+
st.write(advice)
|
| 68 |
+
image_url = create_outfit_image(image_prompt)
|
| 69 |
+
st.image(image_url, caption="Generated Outfit", use_column_width=True)
|
| 70 |
+
else:
|
| 71 |
+
st.error(advice)
|
| 72 |
+
else:
|
| 73 |
+
st.warning("Please enter both a clothing piece and a color.")
|
| 74 |
+
|
| 75 |
+
if __name__ == '__main__':
|
| 76 |
+
main()
|