Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
from diffusers import
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
)
|
| 11 |
-
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 12 |
|
| 13 |
-
#
|
| 14 |
def generate_outfit(weather, activity, style):
|
| 15 |
try:
|
| 16 |
prompt = (
|
| 17 |
f"A realistic full-body outfit for {weather} weather, "
|
| 18 |
-
f"{activity} activity, {style} style, front view,
|
| 19 |
)
|
| 20 |
-
result = pipe(prompt
|
| 21 |
-
image = result.images[0]
|
| 22 |
|
| 23 |
suggestion_text = (
|
| 24 |
f"💡 Suggested outfit for {weather} weather, {activity} activity, {style} style:\n"
|
|
@@ -31,7 +32,7 @@ def generate_outfit(weather, activity, style):
|
|
| 31 |
except Exception as e:
|
| 32 |
return None, f"❌ Error generating outfit: {str(e)}"
|
| 33 |
|
| 34 |
-
# UI
|
| 35 |
custom_css = """
|
| 36 |
body {background: linear-gradient(135deg, #232526, #414345); color: white; font-family: 'Poppins', sans-serif;}
|
| 37 |
.gradio-container {max-width: 900px !important; margin: auto;}
|
|
@@ -74,3 +75,4 @@ with gr.Blocks(css=custom_css) as app:
|
|
| 74 |
app.launch(share=True)
|
| 75 |
|
| 76 |
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
+
from diffusers import DiffusionPipeline
|
| 4 |
|
| 5 |
+
# Load the new model
|
| 6 |
+
# Use bfloat16 for speed and CUDA if available
|
| 7 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 8 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 9 |
+
"black-forest-labs/FLUX.1-dev",
|
| 10 |
+
dtype=torch.bfloat16,
|
| 11 |
+
device_map=device
|
| 12 |
)
|
|
|
|
| 13 |
|
| 14 |
+
# Function to generate outfit image + suggestion
|
| 15 |
def generate_outfit(weather, activity, style):
|
| 16 |
try:
|
| 17 |
prompt = (
|
| 18 |
f"A realistic full-body outfit for {weather} weather, "
|
| 19 |
+
f"{activity} activity, {style} style, front view, fashion style, full body"
|
| 20 |
)
|
| 21 |
+
result = pipe(prompt)
|
| 22 |
+
image = result.images[0]
|
| 23 |
|
| 24 |
suggestion_text = (
|
| 25 |
f"💡 Suggested outfit for {weather} weather, {activity} activity, {style} style:\n"
|
|
|
|
| 32 |
except Exception as e:
|
| 33 |
return None, f"❌ Error generating outfit: {str(e)}"
|
| 34 |
|
| 35 |
+
# Gradio UI
|
| 36 |
custom_css = """
|
| 37 |
body {background: linear-gradient(135deg, #232526, #414345); color: white; font-family: 'Poppins', sans-serif;}
|
| 38 |
.gradio-container {max-width: 900px !important; margin: auto;}
|
|
|
|
| 75 |
app.launch(share=True)
|
| 76 |
|
| 77 |
|
| 78 |
+
|