Spaces:
Running
Running
fix for extra img file
Browse files
app.py
CHANGED
|
@@ -1502,23 +1502,20 @@ def validate_and_autofix_files(files: Dict[str, str]) -> Dict[str, str]:
|
|
| 1502 |
continue
|
| 1503 |
asset_refs.add(ref.lstrip('/'))
|
| 1504 |
|
| 1505 |
-
# Add minimal stubs for missing local references (CSS/JS/images
|
| 1506 |
for ref in list(asset_refs):
|
| 1507 |
if ref not in normalized:
|
| 1508 |
if ref.lower().endswith('.css'):
|
| 1509 |
normalized[ref] = "/* generated stub */\n"
|
| 1510 |
elif ref.lower().endswith('.js'):
|
| 1511 |
normalized[ref] = "// generated stub\n"
|
| 1512 |
-
elif any(ref.lower().endswith(ext) for ext in ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp']):
|
| 1513 |
-
# Use a tiny inline SVG as placeholder content
|
| 1514 |
-
normalized[ref] = (
|
| 1515 |
-
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"1\" height=\"1\"></svg>\n"
|
| 1516 |
-
)
|
| 1517 |
elif ref.lower().endswith('.html'):
|
| 1518 |
normalized[ref] = (
|
| 1519 |
"<!DOCTYPE html>\n<html lang=\"en\">\n<head><meta charset=\"utf-8\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/><title>Page</title></head>\n"
|
| 1520 |
"<body><main><h1>Placeholder page</h1><p>This page was auto-created to satisfy an internal link.</p></main></body>\n</html>"
|
| 1521 |
)
|
|
|
|
|
|
|
| 1522 |
|
| 1523 |
return normalized
|
| 1524 |
|
|
@@ -4418,106 +4415,8 @@ This will help me create a better design for you."""
|
|
| 4418 |
elif language == "svelte":
|
| 4419 |
files = parse_svelte_output(clean_code)
|
| 4420 |
if files['src/App.svelte'] and files['src/app.css']:
|
| 4421 |
-
#
|
| 4422 |
-
|
| 4423 |
-
# For Svelte, we'll add a script section that generates images dynamically
|
| 4424 |
-
# This is more appropriate for Svelte than trying to inject static images
|
| 4425 |
-
image_generation_script = """
|
| 4426 |
-
<script>
|
| 4427 |
-
import { onMount } from 'svelte';
|
| 4428 |
-
|
| 4429 |
-
let generatedImages = [];
|
| 4430 |
-
|
| 4431 |
-
onMount(async () => {
|
| 4432 |
-
// Generate images using Qwen API based on the user prompt
|
| 4433 |
-
const userPrompt = """ + repr(query) + """;
|
| 4434 |
-
|
| 4435 |
-
// Create variations for multiple images
|
| 4436 |
-
const imagePrompts = [
|
| 4437 |
-
userPrompt,
|
| 4438 |
-
`Visual representation of ${userPrompt}`,
|
| 4439 |
-
`Illustration of ${userPrompt}`
|
| 4440 |
-
];
|
| 4441 |
-
|
| 4442 |
-
for (const prompt of imagePrompts) {
|
| 4443 |
-
try {
|
| 4444 |
-
// This would need to be implemented with actual API calls
|
| 4445 |
-
// For now, we'll create placeholder elements
|
| 4446 |
-
generatedImages = [...generatedImages, {
|
| 4447 |
-
prompt: prompt,
|
| 4448 |
-
src: `data:image/svg+xml;base64,${btoa('<svg xmlns="http://www.w3.org/2000/svg" width="300" height="200"><rect width="100%" height="100%" fill="#f0f0f0"/><text x="50%" y="50%" text-anchor="middle" dy=".3em" fill="#666">Generated: ${prompt}</text></svg>')}`,
|
| 4449 |
-
alt: prompt
|
| 4450 |
-
}];
|
| 4451 |
-
} catch (error) {
|
| 4452 |
-
console.error('Error generating image:', error);
|
| 4453 |
-
}
|
| 4454 |
-
}
|
| 4455 |
-
});
|
| 4456 |
-
</script>
|
| 4457 |
-
|
| 4458 |
-
<!-- Generated Images Section -->
|
| 4459 |
-
{#if generatedImages.length > 0}
|
| 4460 |
-
<div class="generated-images">
|
| 4461 |
-
<h3>Generated Images</h3>
|
| 4462 |
-
<div class="image-grid">
|
| 4463 |
-
{#each generatedImages as image}
|
| 4464 |
-
<img src={image.src} alt={image.alt} style="max-width: 100%; height: auto; border-radius: 8px; margin: 10px 0;" />
|
| 4465 |
-
{/each}
|
| 4466 |
-
</div>
|
| 4467 |
-
</div>
|
| 4468 |
-
{/if}"""
|
| 4469 |
-
|
| 4470 |
-
# Add the image generation script to App.svelte
|
| 4471 |
-
if '<script>' in files['src/App.svelte']:
|
| 4472 |
-
# Find the end of the script section and add after it
|
| 4473 |
-
script_end = files['src/App.svelte'].find('</script>') + 8
|
| 4474 |
-
files['src/App.svelte'] = files['src/App.svelte'][:script_end] + '\n' + image_generation_script + files['src/App.svelte'][script_end:]
|
| 4475 |
-
else:
|
| 4476 |
-
# Add script section at the beginning
|
| 4477 |
-
files['src/App.svelte'] = image_generation_script + '\n\n' + files['src/App.svelte']
|
| 4478 |
-
|
| 4479 |
-
# Add CSS for generated images
|
| 4480 |
-
image_css = """
|
| 4481 |
-
/* Generated Images Styling */
|
| 4482 |
-
.generated-images {
|
| 4483 |
-
margin: 20px 0;
|
| 4484 |
-
padding: 20px;
|
| 4485 |
-
background: #f8f9fa;
|
| 4486 |
-
border-radius: 8px;
|
| 4487 |
-
border: 1px solid #e9ecef;
|
| 4488 |
-
}
|
| 4489 |
-
|
| 4490 |
-
.generated-images h3 {
|
| 4491 |
-
margin: 0 0 15px 0;
|
| 4492 |
-
color: #495057;
|
| 4493 |
-
font-size: 1.2em;
|
| 4494 |
-
}
|
| 4495 |
-
|
| 4496 |
-
.image-grid {
|
| 4497 |
-
display: grid;
|
| 4498 |
-
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
| 4499 |
-
gap: 15px;
|
| 4500 |
-
align-items: start;
|
| 4501 |
-
}
|
| 4502 |
-
|
| 4503 |
-
.image-grid img {
|
| 4504 |
-
width: 100%;
|
| 4505 |
-
height: auto;
|
| 4506 |
-
border-radius: 8px;
|
| 4507 |
-
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
| 4508 |
-
transition: transform 0.2s ease;
|
| 4509 |
-
}
|
| 4510 |
-
|
| 4511 |
-
.image-grid img:hover {
|
| 4512 |
-
transform: scale(1.02);
|
| 4513 |
-
}
|
| 4514 |
-
"""
|
| 4515 |
-
|
| 4516 |
-
# Add CSS to app.css
|
| 4517 |
-
if files['src/app.css']:
|
| 4518 |
-
files['src/app.css'] += '\n' + image_css
|
| 4519 |
-
else:
|
| 4520 |
-
files['src/app.css'] = image_css
|
| 4521 |
|
| 4522 |
formatted_output = format_svelte_output(files)
|
| 4523 |
yield {
|
|
@@ -4566,24 +4465,29 @@ This will help me create a better design for you."""
|
|
| 4566 |
}
|
| 4567 |
else:
|
| 4568 |
# Apply media generation (images/video/music)
|
| 4569 |
-
|
| 4570 |
-
|
| 4571 |
-
|
| 4572 |
-
|
| 4573 |
-
|
| 4574 |
-
|
| 4575 |
-
|
| 4576 |
-
|
| 4577 |
-
|
| 4578 |
-
|
| 4579 |
-
|
| 4580 |
-
|
| 4581 |
-
|
| 4582 |
-
|
| 4583 |
-
|
| 4584 |
-
|
| 4585 |
-
|
| 4586 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4587 |
|
| 4588 |
preview_val = None
|
| 4589 |
if language == "html":
|
|
|
|
| 1502 |
continue
|
| 1503 |
asset_refs.add(ref.lstrip('/'))
|
| 1504 |
|
| 1505 |
+
# Add minimal stubs for missing local references (CSS/JS/pages only, not images)
|
| 1506 |
for ref in list(asset_refs):
|
| 1507 |
if ref not in normalized:
|
| 1508 |
if ref.lower().endswith('.css'):
|
| 1509 |
normalized[ref] = "/* generated stub */\n"
|
| 1510 |
elif ref.lower().endswith('.js'):
|
| 1511 |
normalized[ref] = "// generated stub\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1512 |
elif ref.lower().endswith('.html'):
|
| 1513 |
normalized[ref] = (
|
| 1514 |
"<!DOCTYPE html>\n<html lang=\"en\">\n<head><meta charset=\"utf-8\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"/><title>Page</title></head>\n"
|
| 1515 |
"<body><main><h1>Placeholder page</h1><p>This page was auto-created to satisfy an internal link.</p></main></body>\n</html>"
|
| 1516 |
)
|
| 1517 |
+
# Note: We no longer create placeholder image files automatically
|
| 1518 |
+
# This prevents unwanted SVG stub files from being generated during image generation
|
| 1519 |
|
| 1520 |
return normalized
|
| 1521 |
|
|
|
|
| 4415 |
elif language == "svelte":
|
| 4416 |
files = parse_svelte_output(clean_code)
|
| 4417 |
if files['src/App.svelte'] and files['src/app.css']:
|
| 4418 |
+
# Note: Media generation (text-to-image, image-to-image, etc.) is not supported for Svelte apps
|
| 4419 |
+
# Only static HTML apps support automatic image/video/audio generation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4420 |
|
| 4421 |
formatted_output = format_svelte_output(files)
|
| 4422 |
yield {
|
|
|
|
| 4465 |
}
|
| 4466 |
else:
|
| 4467 |
# Apply media generation (images/video/music)
|
| 4468 |
+
# Only apply media generation to static HTML apps, not Svelte/React/other frameworks
|
| 4469 |
+
if language == "html":
|
| 4470 |
+
print("[Generate] Applying post-generation media to static HTML content")
|
| 4471 |
+
final_content = apply_generated_media_to_html(
|
| 4472 |
+
clean_code,
|
| 4473 |
+
query,
|
| 4474 |
+
enable_text_to_image=enable_image_generation,
|
| 4475 |
+
enable_image_to_image=enable_image_to_image,
|
| 4476 |
+
input_image_data=gen_image,
|
| 4477 |
+
image_to_image_prompt=image_to_image_prompt,
|
| 4478 |
+
text_to_image_prompt=text_to_image_prompt,
|
| 4479 |
+
enable_image_to_video=enable_image_to_video,
|
| 4480 |
+
image_to_video_prompt=image_to_video_prompt,
|
| 4481 |
+
session_id=session_id,
|
| 4482 |
+
enable_text_to_video=enable_text_to_video,
|
| 4483 |
+
text_to_video_prompt=text_to_video_prompt,
|
| 4484 |
+
enable_text_to_music=enable_text_to_music,
|
| 4485 |
+
text_to_music_prompt=text_to_music_prompt,
|
| 4486 |
+
token=None,
|
| 4487 |
+
)
|
| 4488 |
+
else:
|
| 4489 |
+
print(f"[Generate] Skipping media generation for {language} apps (only supported for static HTML)")
|
| 4490 |
+
final_content = clean_code
|
| 4491 |
|
| 4492 |
preview_val = None
|
| 4493 |
if language == "html":
|