Spaces:
Running
Running
Fix Gradio 6.0 compatibility: move css/theme from Blocks() to launch()
Browse files
app.py
CHANGED
|
@@ -236,13 +236,11 @@ def chat_edit(message, history):
|
|
| 236 |
if current is None:
|
| 237 |
current = get_default_analysis("shirt")
|
| 238 |
_current_analysis["data"] = current
|
| 239 |
-
# Build edit prompt
|
| 240 |
current_clean = {k: v for k, v in current.items() if k != '_model_used'}
|
| 241 |
edit_prompt = EDIT_PROMPT_TEMPLATE.format(
|
| 242 |
current_json=json.dumps(current_clean, indent=2),
|
| 243 |
user_message=message
|
| 244 |
)
|
| 245 |
-
# Try VLM edit
|
| 246 |
updated = None
|
| 247 |
hf_token = os.environ.get("HF_TOKEN", "")
|
| 248 |
if hf_token:
|
|
@@ -252,7 +250,6 @@ def chat_edit(message, history):
|
|
| 252 |
except Exception as e:
|
| 253 |
print(f"Edit VLM failed: {e}")
|
| 254 |
if updated is None:
|
| 255 |
-
# Simple rule-based fallback for common edits
|
| 256 |
updated = copy.deepcopy(current)
|
| 257 |
msg_lower = message.lower()
|
| 258 |
if "long sleeve" in msg_lower or "longer sleeve" in msg_lower:
|
|
@@ -290,16 +287,13 @@ def chat_edit(message, history):
|
|
| 290 |
if "maxi" in msg_lower:
|
| 291 |
updated['measurements']['skirt_length'] = 110
|
| 292 |
updated['_model_used'] = 'Rule-based edit'
|
| 293 |
-
# Preserve garment type unless explicitly changed
|
| 294 |
if 'garment_type' not in updated:
|
| 295 |
updated['garment_type'] = current.get('garment_type', 'shirt')
|
| 296 |
_current_analysis["data"] = copy.deepcopy(updated)
|
| 297 |
-
# Generate updated outputs
|
| 298 |
try:
|
| 299 |
p2d, p3d, summary, j = _generate_all_outputs(updated)
|
| 300 |
except Exception as e:
|
| 301 |
p2d, p3d, summary, j = None, None, f"Error: {e}", "{}"
|
| 302 |
-
# Build chat response
|
| 303 |
ai_msg = f"Applied edit: {message}\n\n"
|
| 304 |
changes = []
|
| 305 |
old_m = current.get('measurements', {})
|
|
@@ -328,10 +322,10 @@ CSS = """
|
|
| 328 |
.ref-box { padding: 10px; border-radius: 8px; background: #f8f8f8; border: 1px solid #e0e0e0; font-size: 0.85em; }
|
| 329 |
"""
|
| 330 |
|
| 331 |
-
with gr.Blocks(
|
| 332 |
gr.HTML("""
|
| 333 |
<div class="main-header">
|
| 334 |
-
<h1>Garment Pattern Studio</h1>
|
| 335 |
<p style="font-size: 1.1em; color: #555;">
|
| 336 |
Analyze garments, edit with chat, preview in 3D
|
| 337 |
</p>
|
|
@@ -479,4 +473,4 @@ with gr.Blocks(css=CSS, title="Garment Pattern Studio", theme=gr.themes.Soft())
|
|
| 479 |
""")
|
| 480 |
|
| 481 |
if __name__ == "__main__":
|
| 482 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 236 |
if current is None:
|
| 237 |
current = get_default_analysis("shirt")
|
| 238 |
_current_analysis["data"] = current
|
|
|
|
| 239 |
current_clean = {k: v for k, v in current.items() if k != '_model_used'}
|
| 240 |
edit_prompt = EDIT_PROMPT_TEMPLATE.format(
|
| 241 |
current_json=json.dumps(current_clean, indent=2),
|
| 242 |
user_message=message
|
| 243 |
)
|
|
|
|
| 244 |
updated = None
|
| 245 |
hf_token = os.environ.get("HF_TOKEN", "")
|
| 246 |
if hf_token:
|
|
|
|
| 250 |
except Exception as e:
|
| 251 |
print(f"Edit VLM failed: {e}")
|
| 252 |
if updated is None:
|
|
|
|
| 253 |
updated = copy.deepcopy(current)
|
| 254 |
msg_lower = message.lower()
|
| 255 |
if "long sleeve" in msg_lower or "longer sleeve" in msg_lower:
|
|
|
|
| 287 |
if "maxi" in msg_lower:
|
| 288 |
updated['measurements']['skirt_length'] = 110
|
| 289 |
updated['_model_used'] = 'Rule-based edit'
|
|
|
|
| 290 |
if 'garment_type' not in updated:
|
| 291 |
updated['garment_type'] = current.get('garment_type', 'shirt')
|
| 292 |
_current_analysis["data"] = copy.deepcopy(updated)
|
|
|
|
| 293 |
try:
|
| 294 |
p2d, p3d, summary, j = _generate_all_outputs(updated)
|
| 295 |
except Exception as e:
|
| 296 |
p2d, p3d, summary, j = None, None, f"Error: {e}", "{}"
|
|
|
|
| 297 |
ai_msg = f"Applied edit: {message}\n\n"
|
| 298 |
changes = []
|
| 299 |
old_m = current.get('measurements', {})
|
|
|
|
| 322 |
.ref-box { padding: 10px; border-radius: 8px; background: #f8f8f8; border: 1px solid #e0e0e0; font-size: 0.85em; }
|
| 323 |
"""
|
| 324 |
|
| 325 |
+
with gr.Blocks(title="Garment Pattern Studio") as demo:
|
| 326 |
gr.HTML("""
|
| 327 |
<div class="main-header">
|
| 328 |
+
<h1>🧵 Garment Pattern Studio</h1>
|
| 329 |
<p style="font-size: 1.1em; color: #555;">
|
| 330 |
Analyze garments, edit with chat, preview in 3D
|
| 331 |
</p>
|
|
|
|
| 473 |
""")
|
| 474 |
|
| 475 |
if __name__ == "__main__":
|
| 476 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, css=CSS, theme=gr.themes.Soft())
|