Spaces:
Running
Running
only app.py for redesigns
Browse files- backend_deploy.py +35 -2
- frontend/src/components/LandingPage.tsx +2 -2
backend_deploy.py
CHANGED
|
@@ -559,6 +559,26 @@ def deploy_to_huggingface_space(
|
|
| 559 |
|
| 560 |
print(f"[Deploy] Generated {len(files)} file(s): {list(files.keys())}")
|
| 561 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
# Upload all generated files (the LLM is instructed to only output .py files,
|
| 563 |
# but if it creates new assets/data files, we should upload those too)
|
| 564 |
# This approach updates .py files and adds any new files without touching
|
|
@@ -1385,14 +1405,27 @@ Generated by [AnyCoder](https://huggingface.co/spaces/akhaliq/anycoder)"""
|
|
| 1385 |
files["app.py"] = cleaned_code
|
| 1386 |
|
| 1387 |
# For Gradio PRs, only include .py files (preserve existing requirements.txt, etc.)
|
|
|
|
| 1388 |
if language == "gradio":
|
| 1389 |
print(f"[PR] Gradio app - filtering to only .py files")
|
| 1390 |
py_files = {fname: content for fname, content in files.items() if fname.endswith('.py')}
|
| 1391 |
if not py_files:
|
| 1392 |
print(f"[PR] Warning: No .py files found in parsed output")
|
| 1393 |
return False, "No Python files found in generated code for Gradio PR", None
|
| 1394 |
-
|
| 1395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1396 |
|
| 1397 |
# Write files (create subdirectories if needed)
|
| 1398 |
for filename, content in files.items():
|
|
|
|
| 559 |
|
| 560 |
print(f"[Deploy] Generated {len(files)} file(s): {list(files.keys())}")
|
| 561 |
|
| 562 |
+
# For redesign operations, ONLY update app.py to preserve other helper files
|
| 563 |
+
# Detect redesign from commit message OR from history (user prompt contains "redesign")
|
| 564 |
+
is_redesign = False
|
| 565 |
+
if commit_message and "redesign" in commit_message.lower():
|
| 566 |
+
is_redesign = True
|
| 567 |
+
elif history:
|
| 568 |
+
# Check last user message for "redesign" keyword
|
| 569 |
+
for role, content in reversed(history):
|
| 570 |
+
if role == "user" and content and "redesign" in content.lower():
|
| 571 |
+
is_redesign = True
|
| 572 |
+
break
|
| 573 |
+
|
| 574 |
+
if is_redesign:
|
| 575 |
+
print(f"[Deploy] Redesign operation detected - filtering to ONLY app.py")
|
| 576 |
+
app_py_content = files.get('app.py')
|
| 577 |
+
if not app_py_content:
|
| 578 |
+
return False, "Error: No app.py found in redesign output", None
|
| 579 |
+
files = {'app.py': app_py_content}
|
| 580 |
+
print(f"[Deploy] Will only update app.py ({len(app_py_content)} chars)")
|
| 581 |
+
|
| 582 |
# Upload all generated files (the LLM is instructed to only output .py files,
|
| 583 |
# but if it creates new assets/data files, we should upload those too)
|
| 584 |
# This approach updates .py files and adds any new files without touching
|
|
|
|
| 1405 |
files["app.py"] = cleaned_code
|
| 1406 |
|
| 1407 |
# For Gradio PRs, only include .py files (preserve existing requirements.txt, etc.)
|
| 1408 |
+
# For redesigns, ONLY include app.py to avoid modifying helper files
|
| 1409 |
if language == "gradio":
|
| 1410 |
print(f"[PR] Gradio app - filtering to only .py files")
|
| 1411 |
py_files = {fname: content for fname, content in files.items() if fname.endswith('.py')}
|
| 1412 |
if not py_files:
|
| 1413 |
print(f"[PR] Warning: No .py files found in parsed output")
|
| 1414 |
return False, "No Python files found in generated code for Gradio PR", None
|
| 1415 |
+
|
| 1416 |
+
# Check if this is a redesign (pr_title contains "Redesign")
|
| 1417 |
+
is_redesign = "redesign" in pr_title.lower() if pr_title else False
|
| 1418 |
+
|
| 1419 |
+
if is_redesign:
|
| 1420 |
+
print(f"[PR] Redesign PR detected - filtering to ONLY app.py")
|
| 1421 |
+
if 'app.py' not in py_files:
|
| 1422 |
+
print(f"[PR] Warning: No app.py found in redesign output")
|
| 1423 |
+
return False, "No app.py found in redesign output for Gradio PR", None
|
| 1424 |
+
files = {'app.py': py_files['app.py']}
|
| 1425 |
+
print(f"[PR] Will only update app.py ({len(py_files['app.py'])} chars)")
|
| 1426 |
+
else:
|
| 1427 |
+
files = py_files
|
| 1428 |
+
print(f"[PR] Will update {len(files)} Python file(s): {list(files.keys())}")
|
| 1429 |
|
| 1430 |
# Write files (create subdirectories if needed)
|
| 1431 |
for filename, content in files.items():
|
frontend/src/components/LandingPage.tsx
CHANGED
|
@@ -385,7 +385,7 @@ Please redesign this with:
|
|
| 385 |
- Modern UI/UX best practices
|
| 386 |
- Better visual hierarchy and spacing
|
| 387 |
|
| 388 |
-
${isGradio ? '\n\nIMPORTANT: Only output
|
| 389 |
|
| 390 |
if (onStart) {
|
| 391 |
// Pass duplicated space ID so auto-deploy updates it
|
|
@@ -429,7 +429,7 @@ Please redesign this with:
|
|
| 429 |
- Modern UI/UX best practices
|
| 430 |
- Better visual hierarchy and spacing
|
| 431 |
|
| 432 |
-
${isGradio ? '\n\nIMPORTANT: Only output
|
| 433 |
|
| 434 |
Note: After generating the redesign, I will create a Pull Request on the original space.`;
|
| 435 |
|
|
|
|
| 385 |
- Modern UI/UX best practices
|
| 386 |
- Better visual hierarchy and spacing
|
| 387 |
|
| 388 |
+
${isGradio ? '\n\nIMPORTANT: Only output app.py with the redesigned UI (themes, layout, styling). Do NOT modify or output any other .py files (utils.py, models.py, etc.). Do NOT include requirements.txt or README.md.' : ''}`;
|
| 389 |
|
| 390 |
if (onStart) {
|
| 391 |
// Pass duplicated space ID so auto-deploy updates it
|
|
|
|
| 429 |
- Modern UI/UX best practices
|
| 430 |
- Better visual hierarchy and spacing
|
| 431 |
|
| 432 |
+
${isGradio ? '\n\nIMPORTANT: Only output app.py with the redesigned UI (themes, layout, styling). Do NOT modify or output any other .py files (utils.py, models.py, etc.). Do NOT include requirements.txt or README.md.' : ''}
|
| 433 |
|
| 434 |
Note: After generating the redesign, I will create a Pull Request on the original space.`;
|
| 435 |
|