Thiwanka01 commited on
Commit
f365457
·
verified ·
1 Parent(s): 8f4fe98

Create fashion_tool.py

Browse files
Files changed (1) hide show
  1. fashion_tool.py +53 -0
fashion_tool.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ from diffusers import StableDiffusionPipeline
4
+ import torch
5
+
6
+ # Load the Stable Diffusion pipeline
7
+ device = "cuda" if torch.cuda.is_available() else "cpu"
8
+ pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5").to(device)
9
+
10
+ def generate_design(mood_board, style_preference, complexity, color_tone):
11
+ # Construct the prompt for the AI model
12
+ prompt = f"A {style_preference} fashion design with {color_tone} tones and complexity level {complexity}. Inspired by high fashion trends."
13
+
14
+ # Add details from the mood board if provided
15
+ if mood_board:
16
+ prompt += " This design also integrates themes from the uploaded mood board."
17
+
18
+ # Generate the image using Stable Diffusion
19
+ with torch.autocast(device):
20
+ image = pipe(prompt).images[0] # Generate the image
21
+
22
+ # Generate a text description
23
+ description = f"Design Style: {style_preference}, Tone: {color_tone}, Complexity: {complexity}"
24
+ return image, description
25
+
26
+ # Create inputs and outputs
27
+ mood_board_input = gr.Image(type="pil", label="Upload Mood Board (optional)")
28
+ style_preference_input = gr.Dropdown(
29
+ choices=["Casual", "Formal", "Sporty", "Bohemian", "Avant-garde"],
30
+ label="Style Preference"
31
+ )
32
+ complexity_input = gr.Slider(1, 10, step=1, label="Complexity Level")
33
+ color_tone_input = gr.Radio(
34
+ choices=["Bright", "Muted", "Neutral", "Pastel"],
35
+ label="Color Tone"
36
+ )
37
+
38
+ outputs = [
39
+ gr.Image(label="Generated Fashion Design"),
40
+ gr.Textbox(label="Design Details")
41
+ ]
42
+
43
+ # Create the Gradio interface
44
+ interface = gr.Interface(
45
+ fn=generate_design,
46
+ inputs=[mood_board_input, style_preference_input, complexity_input, color_tone_input],
47
+ outputs=outputs,
48
+ title="AI-Assisted Designer Tool",
49
+ description="Generate unique fashion designs based on mood boards, style preferences, and other inputs."
50
+ )
51
+
52
+ # Launch the app
53
+ interface.launch()