Spaces:
Sleeping
Sleeping
prgarg007
commited on
Commit
·
8cb2175
1
Parent(s):
0e95032
push
Browse files- app.py +185 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import gradio as gr
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
|
5 |
+
load_dotenv()
|
6 |
+
|
7 |
+
style_transfer_function = gr.load(
|
8 |
+
"prgarg007/ai-style-transfer-dreamsofa",
|
9 |
+
src="spaces",
|
10 |
+
hf_token=os.getenv("HF_TOKEN")
|
11 |
+
)
|
12 |
+
|
13 |
+
def process_with_private_space(swatch_image, product_image, room_image, room_style):
|
14 |
+
"""
|
15 |
+
Call the private space as a function and return the results
|
16 |
+
"""
|
17 |
+
if style_transfer_function is None:
|
18 |
+
return None, None, "Error: Could not connect to the AI processing service. Please try again later."
|
19 |
+
|
20 |
+
if not swatch_image or not product_image or not room_image:
|
21 |
+
return None, None, "Please upload all three images (swatch, product, and room)."
|
22 |
+
|
23 |
+
try:
|
24 |
+
# Call the private space as a function using the API name we defined
|
25 |
+
styled_product, final_result, status_message = style_transfer_function(
|
26 |
+
swatch_image,
|
27 |
+
product_image,
|
28 |
+
room_image,
|
29 |
+
room_style,
|
30 |
+
api_name="process_style_transfer"
|
31 |
+
)
|
32 |
+
|
33 |
+
return styled_product, final_result, status_message
|
34 |
+
|
35 |
+
except Exception as e:
|
36 |
+
return None, None, f"Error processing images: {str(e)}"
|
37 |
+
|
38 |
+
def create_public_interface():
|
39 |
+
"""Create the public interface that uses the private space as a function"""
|
40 |
+
|
41 |
+
with gr.Blocks(
|
42 |
+
title="AI Style Transfer & Room Integration - Public Access",
|
43 |
+
theme=gr.themes.Soft()
|
44 |
+
) as app:
|
45 |
+
|
46 |
+
gr.Markdown("""
|
47 |
+
# 🚀 AI Powered Style Transfer & Room Integration
|
48 |
+
## Public Access Portal
|
49 |
+
|
50 |
+
Transform your furniture with AI-powered style transfer and room integration!
|
51 |
+
|
52 |
+
**How it works:**
|
53 |
+
1. Upload a **swatch image** (fabric/pattern you want to apply)
|
54 |
+
2. Upload a **product image** (furniture piece to style)
|
55 |
+
3. Upload a **room image** (where you want to place the furniture)
|
56 |
+
4. Select your preferred **room style**
|
57 |
+
5. Let AI work its magic! ✨
|
58 |
+
""")
|
59 |
+
|
60 |
+
# Check if the private space is loaded
|
61 |
+
if style_transfer_function is None:
|
62 |
+
gr.Markdown("""
|
63 |
+
⚠️ **Service Currently Unavailable**
|
64 |
+
|
65 |
+
The AI processing service is currently unavailable. This might be due to:
|
66 |
+
- Network connectivity issues
|
67 |
+
- Authentication problems
|
68 |
+
- Service maintenance
|
69 |
+
|
70 |
+
Please try again later or contact support.
|
71 |
+
""")
|
72 |
+
return app
|
73 |
+
|
74 |
+
with gr.Row():
|
75 |
+
with gr.Column(scale=1):
|
76 |
+
gr.Markdown("### 📤 Upload Your Images")
|
77 |
+
|
78 |
+
swatch_input = gr.Image(
|
79 |
+
label="🎨 Swatch/Pattern Image",
|
80 |
+
type="pil",
|
81 |
+
height=200,
|
82 |
+
info="Upload an image of the fabric, pattern, or style you want to apply"
|
83 |
+
)
|
84 |
+
|
85 |
+
product_input = gr.Image(
|
86 |
+
label="📦 Furniture/Product Image",
|
87 |
+
type="pil",
|
88 |
+
height=200,
|
89 |
+
info="Upload an image of the furniture piece you want to restyle"
|
90 |
+
)
|
91 |
+
|
92 |
+
room_input = gr.Image(
|
93 |
+
label="🏠 Room/Background Image",
|
94 |
+
type="pil",
|
95 |
+
height=200,
|
96 |
+
info="Upload an image of the room where you want to place the furniture"
|
97 |
+
)
|
98 |
+
|
99 |
+
room_style = gr.Dropdown(
|
100 |
+
choices=["modern", "vintage", "industrial", "scandinavian", "bohemian", "rustic"],
|
101 |
+
value="modern",
|
102 |
+
label="🎭 Room Style Theme",
|
103 |
+
info="Choose the overall aesthetic style for the room integration"
|
104 |
+
)
|
105 |
+
|
106 |
+
process_btn = gr.Button(
|
107 |
+
"🤖 Transform with AI",
|
108 |
+
variant="primary",
|
109 |
+
size="lg",
|
110 |
+
scale=1
|
111 |
+
)
|
112 |
+
|
113 |
+
gr.Markdown("""
|
114 |
+
### 💡 Tips for Best Results:
|
115 |
+
- Use high-quality, clear images
|
116 |
+
- Ensure good lighting in your photos
|
117 |
+
- Choose images with similar perspectives
|
118 |
+
- Swatch images work best when the pattern/texture is clearly visible
|
119 |
+
""")
|
120 |
+
|
121 |
+
with gr.Column(scale=1):
|
122 |
+
gr.Markdown("### 🎯 AI Generated Results")
|
123 |
+
|
124 |
+
styled_product_output = gr.Image(
|
125 |
+
label="🎨 Step 1: Styled Product",
|
126 |
+
height=300,
|
127 |
+
info="Your furniture with the new style applied"
|
128 |
+
)
|
129 |
+
|
130 |
+
final_output = gr.Image(
|
131 |
+
label="🏆 Step 2: Room Integration",
|
132 |
+
height=300,
|
133 |
+
info="Your styled furniture integrated into the room scene"
|
134 |
+
)
|
135 |
+
|
136 |
+
status_output = gr.Textbox(
|
137 |
+
label="🔄 Processing Status",
|
138 |
+
value="Ready to transform your furniture with AI...",
|
139 |
+
interactive=False,
|
140 |
+
info="Current processing status and any messages"
|
141 |
+
)
|
142 |
+
|
143 |
+
gr.Markdown("""
|
144 |
+
### 🚀 Processing Steps:
|
145 |
+
1. **AI Analysis**: Examines your swatch and product images
|
146 |
+
2. **Style Transfer**: Applies the swatch style to your furniture
|
147 |
+
3. **Room Integration**: Places the styled furniture in your room
|
148 |
+
4. **Final Rendering**: Creates photorealistic results
|
149 |
+
|
150 |
+
*Processing typically takes 30-60 seconds*
|
151 |
+
""")
|
152 |
+
|
153 |
+
# Connect the button to our function that calls the private space
|
154 |
+
process_btn.click(
|
155 |
+
fn=process_with_private_space,
|
156 |
+
inputs=[swatch_input, product_input, room_input, room_style],
|
157 |
+
outputs=[styled_product_output, final_output, status_output],
|
158 |
+
show_progress=True
|
159 |
+
)
|
160 |
+
|
161 |
+
# Add some example information
|
162 |
+
gr.Markdown("""
|
163 |
+
---
|
164 |
+
### 🎨 Example Use Cases:
|
165 |
+
- **Interior Design**: Preview how different fabrics look on your furniture
|
166 |
+
- **E-commerce**: Show products in various styles and room settings
|
167 |
+
- **Home Renovation**: Experiment with different design aesthetics
|
168 |
+
- **Furniture Customization**: Visualize custom upholstery options
|
169 |
+
|
170 |
+
### ⚡ Powered by:
|
171 |
+
- OpenAI DALL-E for image generation
|
172 |
+
- Advanced AI for style analysis and transfer
|
173 |
+
- Gradio for seamless user experience
|
174 |
+
|
175 |
+
### 🔒 Privacy & Security:
|
176 |
+
- Your images are processed securely
|
177 |
+
- No images are permanently stored
|
178 |
+
- Processing happens in real-time
|
179 |
+
""")
|
180 |
+
|
181 |
+
return app
|
182 |
+
|
183 |
+
if __name__ == "__main__":
|
184 |
+
demo = create_public_interface()
|
185 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==5.38.2
|
2 |
+
openai==1.97.1
|
3 |
+
pillow==10.4.0
|
4 |
+
python-dotenv==1.0.1
|