Spaces:
Running
Running
remove media generation and search
Browse files- README.md +0 -7
- app.py +29 -731
- requirements.txt +0 -1
README.md
CHANGED
|
@@ -44,7 +44,6 @@ pip install -r requirements.txt
|
|
| 44 |
3. Set up environment variables:
|
| 45 |
```bash
|
| 46 |
export HF_TOKEN="your_huggingface_token"
|
| 47 |
-
export TAVILY_API_KEY="your_tavily_api_key" # Optional, for web search feature
|
| 48 |
export DASHSCOPE_API_KEY="your_dashscope_api_key" # Required for Qwen3-30B models via DashScope
|
| 49 |
export POE_API_KEY="your_poe_api_key" # Required for GPT-5, Grok-4, and Grok-Code-Fast-1 via Poe
|
| 50 |
export GEMINI_API_KEY="your_gemini_api_key" # Required for Gemini models
|
|
@@ -97,11 +96,6 @@ python app.py
|
|
| 97 |
- **File Upload**: Provide a reference file (PDF, TXT, MD, CSV, DOCX, or image) for code generation or text extraction (OCR for images)
|
| 98 |
- **Website URL**: Enter a URL to extract and redesign the website (HTML and content are analyzed and modernized)
|
| 99 |
|
| 100 |
-
## Web Search Feature
|
| 101 |
-
|
| 102 |
-
- Enable the "Web search" toggle to use Tavily for real-time information (requires TAVILY_API_KEY)
|
| 103 |
-
- Uses advanced search depth for best results
|
| 104 |
-
|
| 105 |
## Code Generation & Modification
|
| 106 |
|
| 107 |
- Generates code in HTML, Python, JS, and more (selectable via dropdown)
|
|
@@ -129,7 +123,6 @@ python app.py
|
|
| 129 |
## Environment Variables
|
| 130 |
|
| 131 |
- `HF_TOKEN`: Your Hugging Face API token (required)
|
| 132 |
-
- `TAVILY_API_KEY`: Your Tavily API key (optional, for web search)
|
| 133 |
- `GEMINI_API_KEY`: Your Google Gemini API key (required to use Gemini models)
|
| 134 |
- `MOONSHOT_API_KEY`: Your Moonshot AI API key (required to use Kimi models)
|
| 135 |
|
|
|
|
| 44 |
3. Set up environment variables:
|
| 45 |
```bash
|
| 46 |
export HF_TOKEN="your_huggingface_token"
|
|
|
|
| 47 |
export DASHSCOPE_API_KEY="your_dashscope_api_key" # Required for Qwen3-30B models via DashScope
|
| 48 |
export POE_API_KEY="your_poe_api_key" # Required for GPT-5, Grok-4, and Grok-Code-Fast-1 via Poe
|
| 49 |
export GEMINI_API_KEY="your_gemini_api_key" # Required for Gemini models
|
|
|
|
| 96 |
- **File Upload**: Provide a reference file (PDF, TXT, MD, CSV, DOCX, or image) for code generation or text extraction (OCR for images)
|
| 97 |
- **Website URL**: Enter a URL to extract and redesign the website (HTML and content are analyzed and modernized)
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
## Code Generation & Modification
|
| 100 |
|
| 101 |
- Generates code in HTML, Python, JS, and more (selectable via dropdown)
|
|
|
|
| 123 |
## Environment Variables
|
| 124 |
|
| 125 |
- `HF_TOKEN`: Your Hugging Face API token (required)
|
|
|
|
| 126 |
- `GEMINI_API_KEY`: Your Google Gemini API key (required to use Gemini models)
|
| 127 |
- `MOONSHOT_API_KEY`: Your Moonshot AI API key (required to use Kimi models)
|
| 128 |
|
app.py
CHANGED
|
@@ -23,7 +23,6 @@ import html
|
|
| 23 |
|
| 24 |
import gradio as gr
|
| 25 |
from huggingface_hub import InferenceClient
|
| 26 |
-
from tavily import TavilyClient
|
| 27 |
from huggingface_hub import HfApi
|
| 28 |
import tempfile
|
| 29 |
from openai import OpenAI
|
|
@@ -1149,66 +1148,6 @@ def validate_video_html(video_html: str) -> bool:
|
|
| 1149 |
except Exception:
|
| 1150 |
return False
|
| 1151 |
|
| 1152 |
-
def llm_place_media(html_content: str, media_html_tag: str, media_kind: str = "image") -> str:
|
| 1153 |
-
"""Ask a lightweight model to produce search/replace blocks that insert media_html_tag in the best spot.
|
| 1154 |
-
|
| 1155 |
-
The model must return ONLY our block format using SEARCH_START/DIVIDER/REPLACE_END.
|
| 1156 |
-
"""
|
| 1157 |
-
try:
|
| 1158 |
-
client = get_inference_client("Qwen/Qwen3-Coder-480B-A35B-Instruct", "auto")
|
| 1159 |
-
system_prompt = (
|
| 1160 |
-
"You are a code editor. Insert the provided media tag into the given HTML in the most semantically appropriate place.\n"
|
| 1161 |
-
"For video elements: prefer replacing placeholder images or inserting in hero sections with proper container divs.\n"
|
| 1162 |
-
"For image elements: prefer replacing placeholder images or inserting near related content.\n"
|
| 1163 |
-
"CRITICAL: Ensure proper HTML structure - videos should be wrapped in appropriate containers.\n"
|
| 1164 |
-
"Return ONLY search/replace blocks using the exact markers: <<<<<<< SEARCH, =======, >>>>>>> REPLACE.\n"
|
| 1165 |
-
"Do NOT include any commentary. Ensure the SEARCH block matches exact lines from the input.\n"
|
| 1166 |
-
"When inserting videos, ensure they are properly contained within semantic HTML elements.\n"
|
| 1167 |
-
)
|
| 1168 |
-
# Truncate very long media tags for LLM prompt only to prevent token limits
|
| 1169 |
-
truncated_media_tag_for_prompt = media_html_tag
|
| 1170 |
-
if len(media_html_tag) > 2000:
|
| 1171 |
-
# For very long data URIs, show structure but truncate the data for LLM prompt
|
| 1172 |
-
if 'data:video/mp4;base64,' in media_html_tag:
|
| 1173 |
-
start_idx = media_html_tag.find('data:video/mp4;base64,')
|
| 1174 |
-
end_idx = media_html_tag.find('"', start_idx)
|
| 1175 |
-
if start_idx != -1 and end_idx != -1:
|
| 1176 |
-
truncated_media_tag_for_prompt = (
|
| 1177 |
-
media_html_tag[:start_idx] +
|
| 1178 |
-
'data:video/mp4;base64,[TRUNCATED_BASE64_DATA]' +
|
| 1179 |
-
media_html_tag[end_idx:]
|
| 1180 |
-
)
|
| 1181 |
-
|
| 1182 |
-
user_payload = (
|
| 1183 |
-
"HTML Document:\n" + html_content + "\n\n" +
|
| 1184 |
-
f"Media ({media_kind}):\n" + truncated_media_tag_for_prompt + "\n\n" +
|
| 1185 |
-
"Produce search/replace blocks now."
|
| 1186 |
-
)
|
| 1187 |
-
messages = [
|
| 1188 |
-
{"role": "system", "content": system_prompt},
|
| 1189 |
-
{"role": "user", "content": user_payload},
|
| 1190 |
-
]
|
| 1191 |
-
completion = client.chat.completions.create(
|
| 1192 |
-
model="Qwen/Qwen3-Coder-480B-A35B-Instruct",
|
| 1193 |
-
messages=messages,
|
| 1194 |
-
max_tokens=2000,
|
| 1195 |
-
temperature=0.2,
|
| 1196 |
-
)
|
| 1197 |
-
text = (completion.choices[0].message.content or "") if completion and completion.choices else ""
|
| 1198 |
-
|
| 1199 |
-
# Replace any truncated placeholders with the original full media HTML
|
| 1200 |
-
if '[TRUNCATED_BASE64_DATA]' in text and 'data:video/mp4;base64,[TRUNCATED_BASE64_DATA]' in truncated_media_tag_for_prompt:
|
| 1201 |
-
# Extract the original base64 data from the full media tag
|
| 1202 |
-
original_start = media_html_tag.find('data:video/mp4;base64,')
|
| 1203 |
-
original_end = media_html_tag.find('"', original_start)
|
| 1204 |
-
if original_start != -1 and original_end != -1:
|
| 1205 |
-
original_data_uri = media_html_tag[original_start:original_end]
|
| 1206 |
-
text = text.replace('data:video/mp4;base64,[TRUNCATED_BASE64_DATA]', original_data_uri)
|
| 1207 |
-
|
| 1208 |
-
return text.strip()
|
| 1209 |
-
except Exception as e:
|
| 1210 |
-
print(f"[LLMPlaceMedia] Fallback due to error: {e}")
|
| 1211 |
-
return ""
|
| 1212 |
|
| 1213 |
# Stricter prompt for GLM-4.5V to ensure a complete, runnable HTML document with no escaped characters
|
| 1214 |
GLM45V_HTML_SYSTEM_PROMPT = """You are an expert front-end developer.
|
|
@@ -1438,102 +1377,6 @@ Requirements:
|
|
| 1438 |
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder
|
| 1439 |
"""
|
| 1440 |
|
| 1441 |
-
SVELTE_SYSTEM_PROMPT_WITH_SEARCH = """You are an expert Svelte developer. You have access to real-time web search.
|
| 1442 |
-
|
| 1443 |
-
File selection policy (dynamic, model-decided):
|
| 1444 |
-
- Generate ONLY the files actually needed for the user's request.
|
| 1445 |
-
- MUST include src/App.svelte (entry component) and src/main.ts (entry point).
|
| 1446 |
-
- Usually include src/app.css for global styles.
|
| 1447 |
-
- Add additional files when needed, e.g. src/lib/*.svelte, src/components/*.svelte, src/stores/*.ts, static/* assets, etc.
|
| 1448 |
-
- Other base template files (package.json, vite.config.ts, tsconfig, svelte.config.js, src/vite-env.d.ts) are provided by the template and should NOT be generated unless explicitly requested by the user.
|
| 1449 |
-
|
| 1450 |
-
CRITICAL: Always generate src/main.ts with correct Svelte 5 syntax:
|
| 1451 |
-
```typescript
|
| 1452 |
-
import './app.css'
|
| 1453 |
-
import App from './App.svelte'
|
| 1454 |
-
|
| 1455 |
-
const app = new App({
|
| 1456 |
-
target: document.getElementById('app')!,
|
| 1457 |
-
})
|
| 1458 |
-
|
| 1459 |
-
export default app
|
| 1460 |
-
```
|
| 1461 |
-
Do NOT use the old mount syntax: `import { mount } from 'svelte'` - this will cause build errors.
|
| 1462 |
-
|
| 1463 |
-
Output format (CRITICAL):
|
| 1464 |
-
- Return ONLY a series of file sections, each starting with a filename line:
|
| 1465 |
-
=== src/App.svelte ===
|
| 1466 |
-
...file content...
|
| 1467 |
-
|
| 1468 |
-
=== src/app.css ===
|
| 1469 |
-
...file content...
|
| 1470 |
-
|
| 1471 |
-
(repeat for all files you decide to create)
|
| 1472 |
-
- Do NOT wrap files in Markdown code fences.
|
| 1473 |
-
|
| 1474 |
-
Dependency policy:
|
| 1475 |
-
- If you import any third-party npm packages, include a package.json at the project root with a "dependencies" section listing them. Keep scripts and devDependencies compatible with the default Svelte + Vite template.
|
| 1476 |
-
|
| 1477 |
-
Requirements:
|
| 1478 |
-
1. Create a modern, responsive Svelte application
|
| 1479 |
-
2. Prefer TypeScript where applicable
|
| 1480 |
-
3. Clean, professional UI and UX
|
| 1481 |
-
4. Mobile-first responsiveness
|
| 1482 |
-
5. Svelte best practices and modern CSS
|
| 1483 |
-
6. Error handling and loading states
|
| 1484 |
-
7. Accessibility best practices
|
| 1485 |
-
8. Use search to apply current best practices
|
| 1486 |
-
9. Keep component structure organized and minimal
|
| 1487 |
-
|
| 1488 |
-
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder
|
| 1489 |
-
"""
|
| 1490 |
-
|
| 1491 |
-
TRANSFORMERS_JS_SYSTEM_PROMPT_WITH_SEARCH = """You are an expert web developer creating a transformers.js application. You have access to real-time web search. When needed, use web search to find the latest information, best practices, or specific technologies for transformers.js.
|
| 1492 |
-
|
| 1493 |
-
You will generate THREE separate files: index.html, index.js, and style.css.
|
| 1494 |
-
|
| 1495 |
-
IMPORTANT: You MUST output ALL THREE files in the following format:
|
| 1496 |
-
|
| 1497 |
-
```html
|
| 1498 |
-
<!-- index.html content here -->
|
| 1499 |
-
```
|
| 1500 |
-
|
| 1501 |
-
```javascript
|
| 1502 |
-
// index.js content here
|
| 1503 |
-
```
|
| 1504 |
-
|
| 1505 |
-
```css
|
| 1506 |
-
/* style.css content here */
|
| 1507 |
-
```
|
| 1508 |
-
|
| 1509 |
-
Requirements:
|
| 1510 |
-
1. Create a modern, responsive web application using transformers.js
|
| 1511 |
-
2. Use the transformers.js library for AI/ML functionality
|
| 1512 |
-
3. Use web search to find current best practices and latest transformers.js features
|
| 1513 |
-
4. Create a clean, professional UI with good user experience
|
| 1514 |
-
5. Make the application fully responsive for mobile devices
|
| 1515 |
-
6. Use modern CSS practices and JavaScript ES6+ features
|
| 1516 |
-
7. Include proper error handling and loading states
|
| 1517 |
-
8. Follow accessibility best practices
|
| 1518 |
-
|
| 1519 |
-
Library import (required): Add the following snippet to index.html to import transformers.js:
|
| 1520 |
-
<script type="module">
|
| 1521 |
-
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.3';
|
| 1522 |
-
</script>
|
| 1523 |
-
|
| 1524 |
-
Device Options: By default, transformers.js runs on CPU (via WASM). For better performance, you can run models on GPU using WebGPU:
|
| 1525 |
-
- CPU (default): const pipe = await pipeline('task', 'model-name');
|
| 1526 |
-
- GPU (WebGPU): const pipe = await pipeline('task', 'model-name', { device: 'webgpu' });
|
| 1527 |
-
|
| 1528 |
-
Consider providing users with a toggle option to choose between CPU and GPU execution based on their browser's WebGPU support.
|
| 1529 |
-
|
| 1530 |
-
The index.html should contain the basic HTML structure and link to the CSS and JS files.
|
| 1531 |
-
The index.js should contain all the JavaScript logic including transformers.js integration.
|
| 1532 |
-
The style.css should contain all the styling for the application.
|
| 1533 |
-
|
| 1534 |
-
Generate complete, working code files as shown above.
|
| 1535 |
-
|
| 1536 |
-
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder"""
|
| 1537 |
|
| 1538 |
# Gradio system prompts will be dynamically populated by update_gradio_system_prompts()
|
| 1539 |
GRADIO_SYSTEM_PROMPT = ""
|
|
@@ -1553,37 +1396,6 @@ GENERIC_SYSTEM_PROMPT = """You are an expert {language} developer. Write clean,
|
|
| 1553 |
|
| 1554 |
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder"""
|
| 1555 |
|
| 1556 |
-
# System prompt with search capability
|
| 1557 |
-
HTML_SYSTEM_PROMPT_WITH_SEARCH = """You are an expert front-end developer. You have access to real-time web search.
|
| 1558 |
-
|
| 1559 |
-
Output a COMPLETE, STANDALONE HTML document that renders directly in a browser. Requirements:
|
| 1560 |
-
- Include <!DOCTYPE html>, <html>, <head>, and <body> with proper nesting
|
| 1561 |
-
- Include all required <link> and <script> tags for any libraries you use
|
| 1562 |
-
- Do NOT escape characters (no \\n, \\t, or escaped quotes). Output raw HTML/JS/CSS.
|
| 1563 |
-
- If you use React or Tailwind, include correct CDN tags
|
| 1564 |
-
- Keep everything in ONE file; inline CSS/JS as needed
|
| 1565 |
-
|
| 1566 |
-
Use web search when needed to find the latest best practices or correct CDN links.
|
| 1567 |
-
|
| 1568 |
-
For website redesign tasks:
|
| 1569 |
-
- Use the provided original HTML code as the starting point for redesign
|
| 1570 |
-
- Preserve all original content, structure, and functionality
|
| 1571 |
-
- Keep the same semantic HTML structure but enhance the styling
|
| 1572 |
-
- Reuse all original images and their URLs from the HTML code
|
| 1573 |
-
- Use web search to find current design trends and best practices for the specific type of website
|
| 1574 |
-
- Create a modern, responsive design with improved typography and spacing
|
| 1575 |
-
- Use modern CSS frameworks and design patterns
|
| 1576 |
-
- Ensure accessibility and mobile responsiveness
|
| 1577 |
-
- Maintain the same navigation and user flow
|
| 1578 |
-
- Enhance the visual design while keeping the original layout structure
|
| 1579 |
-
|
| 1580 |
-
If an image is provided, analyze it and use the visual information to better understand the user's requirements.
|
| 1581 |
-
|
| 1582 |
-
Always respond with code that can be executed or rendered directly.
|
| 1583 |
-
|
| 1584 |
-
Generate complete, working HTML code that can be run immediately.
|
| 1585 |
-
|
| 1586 |
-
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder"""
|
| 1587 |
|
| 1588 |
# Multi-page static HTML project prompt (generic, production-style structure)
|
| 1589 |
MULTIPAGE_HTML_SYSTEM_PROMPT = """You are an expert front-end developer.
|
|
@@ -1624,18 +1436,6 @@ General requirements:
|
|
| 1624 |
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder
|
| 1625 |
"""
|
| 1626 |
|
| 1627 |
-
# Multi-page with search augmentation
|
| 1628 |
-
MULTIPAGE_HTML_SYSTEM_PROMPT_WITH_SEARCH = """You are an expert front-end developer. You have access to real-time web search.
|
| 1629 |
-
|
| 1630 |
-
Create a production-ready MULTI-PAGE website using ONLY HTML, CSS, and vanilla JavaScript. Do NOT use SPA frameworks.
|
| 1631 |
-
|
| 1632 |
-
Follow the same file output format and project structure as specified:
|
| 1633 |
-
=== filename === blocks for each file (no Markdown fences)
|
| 1634 |
-
|
| 1635 |
-
Use search results to apply current best practices in accessibility, semantics, responsive meta tags, and performance (preconnect, responsive images).
|
| 1636 |
-
|
| 1637 |
-
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder
|
| 1638 |
-
"""
|
| 1639 |
|
| 1640 |
# Dynamic multi-page (model decides files) prompts
|
| 1641 |
DYNAMIC_MULTIPAGE_HTML_SYSTEM_PROMPT = """You are an expert front-end developer.
|
|
@@ -1669,22 +1469,7 @@ General requirements:
|
|
| 1669 |
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder
|
| 1670 |
"""
|
| 1671 |
|
| 1672 |
-
DYNAMIC_MULTIPAGE_HTML_SYSTEM_PROMPT_WITH_SEARCH = """You are an expert front-end developer. You have access to real-time web search.
|
| 1673 |
-
|
| 1674 |
-
Create a production-ready website using ONLY HTML, CSS, and vanilla JavaScript. Do NOT use SPA frameworks.
|
| 1675 |
-
|
| 1676 |
-
Follow the same output format and file selection policy as above (=== filename === blocks; model decides which files to create; ensure index.html unless explicitly not needed).
|
| 1677 |
-
|
| 1678 |
-
Use search results to apply current best practices in accessibility, semantics, responsive meta tags, and performance (preconnect, responsive images).
|
| 1679 |
-
|
| 1680 |
-
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder
|
| 1681 |
-
"""
|
| 1682 |
-
|
| 1683 |
-
GENERIC_SYSTEM_PROMPT_WITH_SEARCH = """You are an expert {language} developer. You have access to real-time web search. When needed, use web search to find the latest information, best practices, or specific technologies for {language}.
|
| 1684 |
-
|
| 1685 |
-
Write clean, idiomatic, and runnable {language} code for the user's request. If possible, include comments and best practices. Generate complete, working code that can be run immediately. If the user provides a file or other context, use it as a reference. If the code is for a script or app, make it as self-contained as possible.
|
| 1686 |
|
| 1687 |
-
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder"""
|
| 1688 |
|
| 1689 |
# Follow-up system prompt for modifying existing HTML files
|
| 1690 |
FollowUpSystemPrompt = f"""You are an expert web developer modifying an existing project.
|
|
@@ -2322,14 +2107,6 @@ History = List[Tuple[str, str]]
|
|
| 2322 |
Messages = List[Dict[str, str]]
|
| 2323 |
|
| 2324 |
# Tavily Search Client
|
| 2325 |
-
TAVILY_API_KEY = os.getenv('TAVILY_API_KEY')
|
| 2326 |
-
tavily_client = None
|
| 2327 |
-
if TAVILY_API_KEY:
|
| 2328 |
-
try:
|
| 2329 |
-
tavily_client = TavilyClient(api_key=TAVILY_API_KEY)
|
| 2330 |
-
except Exception as e:
|
| 2331 |
-
print(f"Failed to initialize Tavily client: {e}")
|
| 2332 |
-
tavily_client = None
|
| 2333 |
|
| 2334 |
def history_to_messages(history: History, system: str) -> Messages:
|
| 2335 |
messages = [{'role': 'system', 'content': system}]
|
|
@@ -3477,114 +3254,7 @@ def cleanup_temp_media_files():
|
|
| 3477 |
except Exception as e:
|
| 3478 |
print(f"[TempCleanup] Error during cleanup: {str(e)}")
|
| 3479 |
|
| 3480 |
-
def generate_image_with_hunyuan(prompt: str, image_index: int = 0, token: gr.OAuthToken | None = None) -> str:
|
| 3481 |
-
"""Generate image using Tencent HunyuanImage-2.1 via Hugging Face InferenceClient.
|
| 3482 |
-
|
| 3483 |
-
Uses tencent/HunyuanImage-2.1 via HuggingFace InferenceClient with fal-ai provider.
|
| 3484 |
-
|
| 3485 |
-
Returns an HTML <img> tag whose src is an uploaded temporary URL.
|
| 3486 |
-
"""
|
| 3487 |
-
try:
|
| 3488 |
-
print(f"[Text2Image] Starting HunyuanImage generation with prompt: {prompt[:100]}...")
|
| 3489 |
-
|
| 3490 |
-
# Check for HF_TOKEN
|
| 3491 |
-
hf_token = os.getenv('HF_TOKEN')
|
| 3492 |
-
if not hf_token:
|
| 3493 |
-
print("[Text2Image] Missing HF_TOKEN")
|
| 3494 |
-
return "Error: HF_TOKEN environment variable is not set. Please set it to your Hugging Face API token."
|
| 3495 |
|
| 3496 |
-
from huggingface_hub import InferenceClient
|
| 3497 |
-
from PIL import Image
|
| 3498 |
-
import io as _io
|
| 3499 |
-
|
| 3500 |
-
# Create InferenceClient with fal-ai provider
|
| 3501 |
-
client = InferenceClient(
|
| 3502 |
-
provider="fal-ai",
|
| 3503 |
-
api_key=hf_token,
|
| 3504 |
-
bill_to="huggingface",
|
| 3505 |
-
)
|
| 3506 |
-
|
| 3507 |
-
print("[Text2Image] Making API request to HuggingFace InferenceClient...")
|
| 3508 |
-
|
| 3509 |
-
# Generate image using HunyuanImage-2.1 model
|
| 3510 |
-
image = client.text_to_image(
|
| 3511 |
-
prompt,
|
| 3512 |
-
model="tencent/HunyuanImage-2.1",
|
| 3513 |
-
)
|
| 3514 |
-
|
| 3515 |
-
print(f"[Text2Image] Successfully generated image with size: {image.size}")
|
| 3516 |
-
|
| 3517 |
-
# Resize image to reduce size while maintaining quality
|
| 3518 |
-
max_size = 1024
|
| 3519 |
-
if image.width > max_size or image.height > max_size:
|
| 3520 |
-
image.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 3521 |
-
|
| 3522 |
-
# Convert PIL Image to bytes for upload
|
| 3523 |
-
buffer = _io.BytesIO()
|
| 3524 |
-
# Save as JPEG with good quality
|
| 3525 |
-
image.convert('RGB').save(buffer, format='JPEG', quality=90, optimize=True)
|
| 3526 |
-
image_bytes = buffer.getvalue()
|
| 3527 |
-
|
| 3528 |
-
# Upload and return HTML tag
|
| 3529 |
-
print("[Text2Image] Uploading image to HF...")
|
| 3530 |
-
filename = f"generated_image_{image_index}.jpg"
|
| 3531 |
-
temp_url = upload_media_to_hf(image_bytes, filename, "image", token, use_temp=True)
|
| 3532 |
-
if temp_url.startswith("Error"):
|
| 3533 |
-
print(f"[Text2Image] Upload failed: {temp_url}")
|
| 3534 |
-
return temp_url
|
| 3535 |
-
print(f"[Text2Image] Successfully generated image: {temp_url}")
|
| 3536 |
-
return f"<img src=\"{temp_url}\" alt=\"{prompt}\" style=\"max-width: 100%; height: auto; border-radius: 8px; margin: 10px 0;\" loading=\"lazy\" />"
|
| 3537 |
-
|
| 3538 |
-
except Exception as e:
|
| 3539 |
-
print(f"[Text2Image] Error generating image with HunyuanImage: {str(e)}")
|
| 3540 |
-
return f"Error generating image (text-to-image): {str(e)}"
|
| 3541 |
-
|
| 3542 |
-
def generate_image_with_qwen(prompt: str, image_index: int = 0, token: gr.OAuthToken | None = None) -> str:
|
| 3543 |
-
"""Generate image using Qwen image model via Hugging Face InferenceClient and upload to HF for permanent URL"""
|
| 3544 |
-
try:
|
| 3545 |
-
# Check if HF_TOKEN is available
|
| 3546 |
-
if not os.getenv('HF_TOKEN'):
|
| 3547 |
-
return "Error: HF_TOKEN environment variable is not set. Please set it to your Hugging Face API token."
|
| 3548 |
-
|
| 3549 |
-
# Create InferenceClient for Qwen image generation
|
| 3550 |
-
client = InferenceClient(
|
| 3551 |
-
provider="auto",
|
| 3552 |
-
api_key=os.getenv('HF_TOKEN'),
|
| 3553 |
-
bill_to="huggingface",
|
| 3554 |
-
)
|
| 3555 |
-
|
| 3556 |
-
# Generate image using Qwen/Qwen-Image model
|
| 3557 |
-
image = client.text_to_image(
|
| 3558 |
-
prompt,
|
| 3559 |
-
model="Qwen/Qwen-Image",
|
| 3560 |
-
)
|
| 3561 |
-
|
| 3562 |
-
# Resize image to reduce size while maintaining quality
|
| 3563 |
-
max_size = 1024 # Increased size since we're not using data URIs
|
| 3564 |
-
if image.width > max_size or image.height > max_size:
|
| 3565 |
-
image.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 3566 |
-
|
| 3567 |
-
# Convert PIL Image to bytes for upload
|
| 3568 |
-
import io
|
| 3569 |
-
buffer = io.BytesIO()
|
| 3570 |
-
# Save as JPEG with good quality since we're not embedding
|
| 3571 |
-
image.convert('RGB').save(buffer, format='JPEG', quality=90, optimize=True)
|
| 3572 |
-
image_bytes = buffer.getvalue()
|
| 3573 |
-
|
| 3574 |
-
# Create temporary URL for preview (will be uploaded to HF during deploy)
|
| 3575 |
-
filename = f"generated_image_{image_index}.jpg"
|
| 3576 |
-
temp_url = upload_media_to_hf(image_bytes, filename, "image", token, use_temp=True)
|
| 3577 |
-
|
| 3578 |
-
# Check if creation was successful
|
| 3579 |
-
if temp_url.startswith("Error"):
|
| 3580 |
-
return temp_url
|
| 3581 |
-
|
| 3582 |
-
# Return HTML img tag with temporary URL
|
| 3583 |
-
return f'<img src="{temp_url}" alt="{prompt}" style="max-width: 100%; height: auto; border-radius: 8px; margin: 10px 0;" loading="lazy" />'
|
| 3584 |
-
|
| 3585 |
-
except Exception as e:
|
| 3586 |
-
print(f"Image generation error: {str(e)}")
|
| 3587 |
-
return f"Error generating image: {str(e)}"
|
| 3588 |
|
| 3589 |
def generate_image_to_image(input_image_data, prompt: str, token: gr.OAuthToken | None = None) -> str:
|
| 3590 |
"""Generate an image using image-to-image via OpenRouter.
|
|
@@ -4991,7 +4661,7 @@ def create_video_replacement_blocks_from_input_video(html_content: str, user_pro
|
|
| 4991 |
print("[Video2Video] No <body> tag; appending video via replacement block")
|
| 4992 |
return f"{SEARCH_START}\n\n{DIVIDER}\n{video_html}\n{REPLACE_END}"
|
| 4993 |
|
| 4994 |
-
def
|
| 4995 |
"""Apply text/image/video/music replacements to HTML content.
|
| 4996 |
|
| 4997 |
- Works with single-document HTML strings
|
|
@@ -5501,55 +5171,6 @@ def apply_transformers_js_search_replace_changes(original_formatted_content: str
|
|
| 5501 |
# Updated for faster Tavily search and closer prompt usage
|
| 5502 |
# Uses 'advanced' search_depth and auto_parameters=True for speed and relevance
|
| 5503 |
|
| 5504 |
-
def perform_web_search(query: str, max_results: int = 5, include_domains=None, exclude_domains=None) -> str:
|
| 5505 |
-
"""Perform web search using Tavily with default parameters"""
|
| 5506 |
-
if not tavily_client:
|
| 5507 |
-
return "Web search is not available. Please set the TAVILY_API_KEY environment variable."
|
| 5508 |
-
|
| 5509 |
-
try:
|
| 5510 |
-
# Use Tavily defaults with advanced search depth for better results
|
| 5511 |
-
search_params = {
|
| 5512 |
-
"search_depth": "advanced",
|
| 5513 |
-
"max_results": min(max(1, max_results), 20)
|
| 5514 |
-
}
|
| 5515 |
-
if include_domains is not None:
|
| 5516 |
-
search_params["include_domains"] = include_domains
|
| 5517 |
-
if exclude_domains is not None:
|
| 5518 |
-
search_params["exclude_domains"] = exclude_domains
|
| 5519 |
-
|
| 5520 |
-
response = tavily_client.search(query, **search_params)
|
| 5521 |
-
|
| 5522 |
-
search_results = []
|
| 5523 |
-
for result in response.get('results', []):
|
| 5524 |
-
title = result.get('title', 'No title')
|
| 5525 |
-
url = result.get('url', 'No URL')
|
| 5526 |
-
content = result.get('content', 'No content')
|
| 5527 |
-
search_results.append(f"Title: {title}\nURL: {url}\nContent: {content}\n")
|
| 5528 |
-
|
| 5529 |
-
if search_results:
|
| 5530 |
-
return "Web Search Results:\n\n" + "\n---\n".join(search_results)
|
| 5531 |
-
else:
|
| 5532 |
-
return "No search results found."
|
| 5533 |
-
|
| 5534 |
-
except Exception as e:
|
| 5535 |
-
return f"Search error: {str(e)}"
|
| 5536 |
-
|
| 5537 |
-
def enhance_query_with_search(query: str, enable_search: bool) -> str:
|
| 5538 |
-
"""Enhance the query with web search results if search is enabled"""
|
| 5539 |
-
if not enable_search or not tavily_client:
|
| 5540 |
-
return query
|
| 5541 |
-
|
| 5542 |
-
# Perform search to get relevant information
|
| 5543 |
-
search_results = perform_web_search(query)
|
| 5544 |
-
|
| 5545 |
-
# Combine original query with search results
|
| 5546 |
-
enhanced_query = f"""Original Query: {query}
|
| 5547 |
-
|
| 5548 |
-
{search_results}
|
| 5549 |
-
|
| 5550 |
-
Please use the search results above to help create the requested application with the most up-to-date information and best practices."""
|
| 5551 |
-
|
| 5552 |
-
return enhanced_query
|
| 5553 |
|
| 5554 |
def send_to_sandbox(code):
|
| 5555 |
"""Render HTML in a sandboxed iframe. Assumes full HTML is provided by prompts."""
|
|
@@ -6269,7 +5890,7 @@ def update_ui_for_auth_status(profile: gr.OAuthProfile | None = None, token: gr.
|
|
| 6269 |
}
|
| 6270 |
|
| 6271 |
|
| 6272 |
-
def generation_code(query: str | None, vlm_image: Optional[gr.Image],
|
| 6273 |
# Check authentication first
|
| 6274 |
is_authenticated, auth_message = check_authentication(profile, token)
|
| 6275 |
if not is_authenticated:
|
|
@@ -6450,17 +6071,17 @@ Generate the exact search/replace blocks needed to make these changes."""
|
|
| 6450 |
# Use language-specific prompt
|
| 6451 |
if language == "html":
|
| 6452 |
# Dynamic file selection always enabled
|
| 6453 |
-
system_prompt =
|
| 6454 |
elif language == "transformers.js":
|
| 6455 |
-
system_prompt =
|
| 6456 |
elif language == "svelte":
|
| 6457 |
-
system_prompt =
|
| 6458 |
elif language == "gradio":
|
| 6459 |
-
system_prompt =
|
| 6460 |
elif language == "json":
|
| 6461 |
-
system_prompt =
|
| 6462 |
else:
|
| 6463 |
-
system_prompt =
|
| 6464 |
|
| 6465 |
messages = history_to_messages(_history, system_prompt)
|
| 6466 |
|
|
@@ -6492,8 +6113,8 @@ Since I couldn't extract the website content, please provide additional details
|
|
| 6492 |
This will help me create a better design for you."""
|
| 6493 |
query = f"{query}\n\n[Error extracting website: {website_text}]{fallback_guidance}"
|
| 6494 |
|
| 6495 |
-
#
|
| 6496 |
-
enhanced_query =
|
| 6497 |
|
| 6498 |
# Check if this is GLM-4.5 model and handle with simple HuggingFace InferenceClient
|
| 6499 |
if _current_model["id"] == "zai-org/GLM-4.5":
|
|
@@ -6540,45 +6161,14 @@ This will help me create a better design for you."""
|
|
| 6540 |
|
| 6541 |
clean_code = remove_code_block(content)
|
| 6542 |
|
| 6543 |
-
#
|
| 6544 |
-
|
| 6545 |
-
final_content = apply_generated_media_to_html(
|
| 6546 |
-
clean_code,
|
| 6547 |
-
query,
|
| 6548 |
-
enable_text_to_image=enable_image_generation,
|
| 6549 |
-
enable_image_to_image=enable_image_to_image,
|
| 6550 |
-
input_image_data=gen_image,
|
| 6551 |
-
image_to_image_prompt=image_to_image_prompt,
|
| 6552 |
-
enable_image_to_video=enable_image_to_video,
|
| 6553 |
-
image_to_video_prompt=image_to_video_prompt,
|
| 6554 |
-
session_id=session_id,
|
| 6555 |
-
enable_text_to_video=enable_text_to_video,
|
| 6556 |
-
text_to_video_prompt=text_to_video_prompt,
|
| 6557 |
-
enable_video_to_video=enable_video_to_video,
|
| 6558 |
-
video_to_video_prompt=video_to_video_prompt,
|
| 6559 |
-
input_video_data=input_video_data,
|
| 6560 |
-
enable_text_to_music=enable_text_to_music,
|
| 6561 |
-
text_to_music_prompt=text_to_music_prompt,
|
| 6562 |
-
enable_image_video_to_animation=enable_image_video_to_animation,
|
| 6563 |
-
animation_mode=animation_mode,
|
| 6564 |
-
animation_quality=animation_quality,
|
| 6565 |
-
animation_video_data=animation_video_data,
|
| 6566 |
-
token=None,
|
| 6567 |
-
)
|
| 6568 |
|
| 6569 |
_history.append([query, final_content])
|
| 6570 |
|
| 6571 |
if language == "transformers.js":
|
| 6572 |
files = parse_transformers_js_output(clean_code)
|
| 6573 |
if files['index.html'] and files['index.js'] and files['style.css']:
|
| 6574 |
-
# Apply image generation if enabled
|
| 6575 |
-
if enable_image_generation:
|
| 6576 |
-
# Create search/replace blocks for image replacement based on images found in code
|
| 6577 |
-
image_replacement_blocks = create_image_replacement_blocks(files['index.html'], query)
|
| 6578 |
-
if image_replacement_blocks:
|
| 6579 |
-
# Apply the image replacements using existing search/replace logic
|
| 6580 |
-
files['index.html'] = apply_search_replace_changes(files['index.html'], image_replacement_blocks)
|
| 6581 |
-
|
| 6582 |
formatted_output = format_transformers_js_output(files)
|
| 6583 |
yield {
|
| 6584 |
code_output: formatted_output,
|
|
@@ -6619,31 +6209,7 @@ This will help me create a better design for you."""
|
|
| 6619 |
modified_content = apply_search_replace_changes(last_content, clean_code)
|
| 6620 |
clean_content = remove_code_block(modified_content)
|
| 6621 |
|
| 6622 |
-
#
|
| 6623 |
-
print("[Generate] Applying post-generation media to modified HTML content")
|
| 6624 |
-
clean_content = apply_generated_media_to_html(
|
| 6625 |
-
clean_content,
|
| 6626 |
-
query,
|
| 6627 |
-
enable_text_to_image=enable_image_generation,
|
| 6628 |
-
enable_image_to_image=enable_image_to_image,
|
| 6629 |
-
input_image_data=gen_image,
|
| 6630 |
-
image_to_image_prompt=image_to_image_prompt,
|
| 6631 |
-
enable_image_to_video=enable_image_to_video,
|
| 6632 |
-
image_to_video_prompt=image_to_video_prompt,
|
| 6633 |
-
session_id=session_id,
|
| 6634 |
-
enable_text_to_video=enable_text_to_video,
|
| 6635 |
-
text_to_video_prompt=text_to_video_prompt,
|
| 6636 |
-
enable_video_to_video=enable_video_to_video,
|
| 6637 |
-
video_to_video_prompt=video_to_video_prompt,
|
| 6638 |
-
input_video_data=input_video_data,
|
| 6639 |
-
enable_text_to_music=enable_text_to_music,
|
| 6640 |
-
text_to_music_prompt=text_to_music_prompt,
|
| 6641 |
-
enable_image_video_to_animation=enable_image_video_to_animation,
|
| 6642 |
-
animation_mode=animation_mode,
|
| 6643 |
-
animation_quality=animation_quality,
|
| 6644 |
-
animation_video_data=animation_video_data,
|
| 6645 |
-
token=None,
|
| 6646 |
-
)
|
| 6647 |
|
| 6648 |
yield {
|
| 6649 |
code_output: clean_content,
|
|
@@ -6652,37 +6218,8 @@ This will help me create a better design for you."""
|
|
| 6652 |
history_output: history_to_chatbot_messages(_history),
|
| 6653 |
}
|
| 6654 |
else:
|
| 6655 |
-
#
|
| 6656 |
-
|
| 6657 |
-
if language == "html":
|
| 6658 |
-
print("[Generate] Applying post-generation media to static HTML content")
|
| 6659 |
-
final_content = apply_generated_media_to_html(
|
| 6660 |
-
clean_code,
|
| 6661 |
-
query,
|
| 6662 |
-
enable_text_to_image=enable_image_generation,
|
| 6663 |
-
enable_image_to_image=enable_image_to_image,
|
| 6664 |
-
input_image_data=gen_image,
|
| 6665 |
-
image_to_image_prompt=image_to_image_prompt,
|
| 6666 |
-
text_to_image_prompt=text_to_image_prompt,
|
| 6667 |
-
enable_image_to_video=enable_image_to_video,
|
| 6668 |
-
image_to_video_prompt=image_to_video_prompt,
|
| 6669 |
-
session_id=session_id,
|
| 6670 |
-
enable_text_to_video=enable_text_to_video,
|
| 6671 |
-
text_to_video_prompt=text_to_video_prompt,
|
| 6672 |
-
enable_video_to_video=enable_video_to_video,
|
| 6673 |
-
video_to_video_prompt=video_to_video_prompt,
|
| 6674 |
-
input_video_data=input_video_data,
|
| 6675 |
-
enable_text_to_music=enable_text_to_music,
|
| 6676 |
-
text_to_music_prompt=text_to_music_prompt,
|
| 6677 |
-
enable_image_video_to_animation=enable_image_video_to_animation,
|
| 6678 |
-
animation_mode=animation_mode,
|
| 6679 |
-
animation_quality=animation_quality,
|
| 6680 |
-
animation_video_data=animation_video_data,
|
| 6681 |
-
token=None,
|
| 6682 |
-
)
|
| 6683 |
-
else:
|
| 6684 |
-
print(f"[Generate] Skipping media generation for {language} apps (only supported for static HTML)")
|
| 6685 |
-
final_content = clean_code
|
| 6686 |
|
| 6687 |
preview_val = None
|
| 6688 |
if language == "html":
|
|
@@ -6920,7 +6457,7 @@ This will help me create a better design for you."""
|
|
| 6920 |
else:
|
| 6921 |
# Append content, filtering out placeholder thinking lines
|
| 6922 |
content += strip_placeholder_thinking(chunk_content)
|
| 6923 |
-
search_status = "
|
| 6924 |
|
| 6925 |
# Handle transformers.js output differently
|
| 6926 |
if language == "transformers.js":
|
|
@@ -7099,32 +6636,7 @@ This will help me create a better design for you."""
|
|
| 7099 |
modified_content = apply_search_replace_changes(last_content, final_code)
|
| 7100 |
clean_content = remove_code_block(modified_content)
|
| 7101 |
|
| 7102 |
-
#
|
| 7103 |
-
print("[Generate] Applying post-generation media to follow-up HTML content")
|
| 7104 |
-
clean_content = apply_generated_media_to_html(
|
| 7105 |
-
clean_content,
|
| 7106 |
-
query,
|
| 7107 |
-
enable_text_to_image=enable_image_generation,
|
| 7108 |
-
enable_image_to_image=enable_image_to_image,
|
| 7109 |
-
input_image_data=gen_image,
|
| 7110 |
-
image_to_image_prompt=image_to_image_prompt,
|
| 7111 |
-
enable_image_to_video=enable_image_to_video,
|
| 7112 |
-
image_to_video_prompt=image_to_video_prompt,
|
| 7113 |
-
session_id=session_id,
|
| 7114 |
-
text_to_image_prompt=text_to_image_prompt,
|
| 7115 |
-
enable_text_to_video=enable_text_to_video,
|
| 7116 |
-
text_to_video_prompt=text_to_video_prompt,
|
| 7117 |
-
enable_video_to_video=enable_video_to_video,
|
| 7118 |
-
video_to_video_prompt=video_to_video_prompt,
|
| 7119 |
-
input_video_data=input_video_data,
|
| 7120 |
-
enable_text_to_music=enable_text_to_music,
|
| 7121 |
-
text_to_music_prompt=text_to_music_prompt,
|
| 7122 |
-
enable_image_video_to_animation=enable_image_video_to_animation,
|
| 7123 |
-
animation_mode=animation_mode,
|
| 7124 |
-
animation_quality=animation_quality,
|
| 7125 |
-
animation_video_data=animation_video_data,
|
| 7126 |
-
token=None,
|
| 7127 |
-
)
|
| 7128 |
|
| 7129 |
# Update history with the cleaned content
|
| 7130 |
_history.append([query, clean_content])
|
|
@@ -7138,32 +6650,7 @@ This will help me create a better design for you."""
|
|
| 7138 |
# Regular generation - use the content as is
|
| 7139 |
final_content = remove_code_block(content)
|
| 7140 |
|
| 7141 |
-
#
|
| 7142 |
-
print("[Generate] Applying post-generation media to final HTML content")
|
| 7143 |
-
final_content = apply_generated_media_to_html(
|
| 7144 |
-
final_content,
|
| 7145 |
-
query,
|
| 7146 |
-
enable_text_to_image=enable_image_generation,
|
| 7147 |
-
enable_image_to_image=enable_image_to_image,
|
| 7148 |
-
input_image_data=gen_image,
|
| 7149 |
-
image_to_image_prompt=image_to_image_prompt,
|
| 7150 |
-
text_to_image_prompt=text_to_image_prompt,
|
| 7151 |
-
enable_image_to_video=enable_image_to_video,
|
| 7152 |
-
image_to_video_prompt=image_to_video_prompt,
|
| 7153 |
-
session_id=session_id,
|
| 7154 |
-
enable_text_to_video=enable_text_to_video,
|
| 7155 |
-
text_to_video_prompt=text_to_video_prompt,
|
| 7156 |
-
enable_video_to_video=enable_video_to_video,
|
| 7157 |
-
video_to_video_prompt=video_to_video_prompt,
|
| 7158 |
-
input_video_data=input_video_data,
|
| 7159 |
-
enable_text_to_music=enable_text_to_music,
|
| 7160 |
-
text_to_music_prompt=text_to_music_prompt,
|
| 7161 |
-
enable_image_video_to_animation=enable_image_video_to_animation,
|
| 7162 |
-
animation_mode=animation_mode,
|
| 7163 |
-
animation_quality=animation_quality,
|
| 7164 |
-
animation_video_data=animation_video_data,
|
| 7165 |
-
token=None,
|
| 7166 |
-
)
|
| 7167 |
|
| 7168 |
_history.append([query, final_content])
|
| 7169 |
preview_val = None
|
|
@@ -8262,19 +7749,14 @@ with gr.Blocks(
|
|
| 8262 |
value=(
|
| 8263 |
"### Command Reference\n"
|
| 8264 |
"- **Language**: 'use streamlit' | 'use gradio' | 'use html'\n"
|
| 8265 |
-
"- **Web search**: 'enable web search' | 'disable web search'\n"
|
| 8266 |
"- **Model**: 'model <name>' (exact match to items in the Model dropdown)\n"
|
| 8267 |
"- **Website redesign**: include a URL in your message (e.g., 'https://example.com')\n"
|
| 8268 |
-
"- **
|
| 8269 |
-
"- **Image → Image**: 'image to image: <prompt>' (attach an image)\n"
|
| 8270 |
-
"- **Image → Video**: 'image to video: <prompt>' (attach an image)\n"
|
| 8271 |
-
"- **Text → Video**: 'text to video: <prompt>' or 'generate video: <prompt>'\n"
|
| 8272 |
-
"- **Files & media**: attach documents or images directly; the first image is used for generation, the first non-image is treated as a reference file\n"
|
| 8273 |
"- **Multiple directives**: separate with commas. The first segment is the main build prompt.\n\n"
|
| 8274 |
"Examples:\n"
|
| 8275 |
-
"- anycoder coffee shop
|
| 8276 |
-
"- redesign https://example.com, use streamlit
|
| 8277 |
-
"- dashboard ui
|
| 8278 |
)
|
| 8279 |
)
|
| 8280 |
|
|
@@ -8332,21 +7814,11 @@ with gr.Blocks(
|
|
| 8332 |
label="UI design image",
|
| 8333 |
visible=False
|
| 8334 |
)
|
| 8335 |
-
#
|
| 8336 |
-
generation_image_input = gr.Image(
|
| 8337 |
-
label="image for generation",
|
| 8338 |
-
visible=False
|
| 8339 |
-
)
|
| 8340 |
-
image_to_image_prompt = gr.Textbox(
|
| 8341 |
-
label="Image-to-Image Prompt",
|
| 8342 |
-
placeholder="Describe how to transform the uploaded image (e.g., 'Turn the cat into a tiger.')",
|
| 8343 |
-
lines=2,
|
| 8344 |
-
visible=False
|
| 8345 |
-
)
|
| 8346 |
with gr.Row():
|
| 8347 |
btn = gr.Button("Generate", variant="secondary", size="lg", scale=2, visible=True, interactive=False)
|
| 8348 |
clear_btn = gr.Button("Clear", variant="secondary", size="sm", scale=1, visible=True)
|
| 8349 |
-
# ---
|
| 8350 |
space_name_input = gr.Textbox(
|
| 8351 |
label="app name (e.g. my-cool-app)",
|
| 8352 |
placeholder="Enter your app name",
|
|
@@ -8369,181 +7841,9 @@ with gr.Blocks(
|
|
| 8369 |
deploy_btn = gr.Button("🚀 Deploy App", variant="primary", visible=False)
|
| 8370 |
deploy_status = gr.Markdown(visible=False, label="Deploy status")
|
| 8371 |
# --- End move ---
|
| 8372 |
-
|
| 8373 |
-
label="🔍 Web search",
|
| 8374 |
-
value=False,
|
| 8375 |
-
visible=True
|
| 8376 |
-
)
|
| 8377 |
-
# Dynamic multipage is always enabled; no toggle in UI
|
| 8378 |
-
# Image generation toggles
|
| 8379 |
-
image_generation_toggle = gr.Checkbox(
|
| 8380 |
-
label="🎨 Generate Images (text → image)",
|
| 8381 |
-
value=False,
|
| 8382 |
-
visible=True,
|
| 8383 |
-
info="Include generated images in your outputs using HunyuanImage-2.1"
|
| 8384 |
-
)
|
| 8385 |
-
text_to_image_prompt = gr.Textbox(
|
| 8386 |
-
label="Text-to-Image Prompt",
|
| 8387 |
-
placeholder="Describe the image to generate (e.g., 'A minimalist dashboard hero illustration in pastel colors.')",
|
| 8388 |
-
lines=2,
|
| 8389 |
-
visible=False
|
| 8390 |
-
)
|
| 8391 |
-
image_to_image_toggle = gr.Checkbox(
|
| 8392 |
-
label="🖼️ Image to Image (uses input image)",
|
| 8393 |
-
value=False,
|
| 8394 |
-
visible=True,
|
| 8395 |
-
info="Transform your uploaded image using Nano Banana"
|
| 8396 |
-
)
|
| 8397 |
-
image_to_video_toggle = gr.Checkbox(
|
| 8398 |
-
label="🎞️ Image to Video (uses input image)",
|
| 8399 |
-
value=False,
|
| 8400 |
-
visible=True,
|
| 8401 |
-
info="Generate a short video from your uploaded image using Lightricks LTX-Video"
|
| 8402 |
-
)
|
| 8403 |
-
image_to_video_prompt = gr.Textbox(
|
| 8404 |
-
label="Image-to-Video Prompt",
|
| 8405 |
-
placeholder="Describe the motion (e.g., 'The cat starts to dance')",
|
| 8406 |
-
lines=2,
|
| 8407 |
-
visible=False
|
| 8408 |
-
)
|
| 8409 |
-
|
| 8410 |
-
# Text-to-Video
|
| 8411 |
-
text_to_video_toggle = gr.Checkbox(
|
| 8412 |
-
label="📹 Generate Video (text → video)",
|
| 8413 |
-
value=False,
|
| 8414 |
-
visible=True,
|
| 8415 |
-
info="Generate a short video directly from your prompt using Wan-AI/Wan2.2-TI2V-5B"
|
| 8416 |
-
)
|
| 8417 |
-
text_to_video_prompt = gr.Textbox(
|
| 8418 |
-
label="Text-to-Video Prompt",
|
| 8419 |
-
placeholder="Describe the video to generate (e.g., 'A young man walking on the street')",
|
| 8420 |
-
lines=2,
|
| 8421 |
-
visible=False
|
| 8422 |
-
)
|
| 8423 |
-
|
| 8424 |
-
# Video-to-Video
|
| 8425 |
-
video_to_video_toggle = gr.Checkbox(
|
| 8426 |
-
label="🎬 Video to Video (uses input video)",
|
| 8427 |
-
value=False,
|
| 8428 |
-
visible=True,
|
| 8429 |
-
info="Transform your uploaded video using Decart AI's Lucy Pro V2V"
|
| 8430 |
-
)
|
| 8431 |
-
video_to_video_prompt = gr.Textbox(
|
| 8432 |
-
label="Video-to-Video Prompt",
|
| 8433 |
-
placeholder="Describe the transformation (e.g., 'Change their shirt to black and shiny leather')",
|
| 8434 |
-
lines=2,
|
| 8435 |
-
visible=False
|
| 8436 |
-
)
|
| 8437 |
-
video_input = gr.Video(
|
| 8438 |
-
label="Input video for transformation",
|
| 8439 |
-
visible=False
|
| 8440 |
-
)
|
| 8441 |
|
| 8442 |
-
#
|
| 8443 |
-
text_to_music_toggle = gr.Checkbox(
|
| 8444 |
-
label="🎵 Generate Music (text → music)",
|
| 8445 |
-
value=False,
|
| 8446 |
-
visible=True,
|
| 8447 |
-
info="Compose short music from your prompt using ElevenLabs Music"
|
| 8448 |
-
)
|
| 8449 |
-
text_to_music_prompt = gr.Textbox(
|
| 8450 |
-
label="Text-to-Music Prompt",
|
| 8451 |
-
placeholder="Describe the music to generate (e.g., 'Epic orchestral theme with soaring strings and powerful brass')",
|
| 8452 |
-
lines=2,
|
| 8453 |
-
visible=False
|
| 8454 |
-
)
|
| 8455 |
-
|
| 8456 |
-
# Image+Video to Animation
|
| 8457 |
-
image_video_to_animation_toggle = gr.Checkbox(
|
| 8458 |
-
label="🎭 Character Animation (uses input image + video)",
|
| 8459 |
-
value=False,
|
| 8460 |
-
visible=True,
|
| 8461 |
-
info="Animate characters using Wan2.2-Animate with reference image and template video"
|
| 8462 |
-
)
|
| 8463 |
-
animation_mode_dropdown = gr.Dropdown(
|
| 8464 |
-
label="Animation Mode",
|
| 8465 |
-
choices=[
|
| 8466 |
-
("Move Mode (animate character with video motion)", "wan2.2-animate-move"),
|
| 8467 |
-
("Mix Mode (replace character in video)", "wan2.2-animate-mix")
|
| 8468 |
-
],
|
| 8469 |
-
value="wan2.2-animate-move",
|
| 8470 |
-
visible=False,
|
| 8471 |
-
info="Move: animate image character with video motion. Mix: replace video character with image character"
|
| 8472 |
-
)
|
| 8473 |
-
animation_quality_dropdown = gr.Dropdown(
|
| 8474 |
-
label="Animation Quality",
|
| 8475 |
-
choices=[
|
| 8476 |
-
("Professional (25fps, 720p)", "wan-pro"),
|
| 8477 |
-
("Standard (15fps, 720p)", "wan-std")
|
| 8478 |
-
],
|
| 8479 |
-
value="wan-pro",
|
| 8480 |
-
visible=False,
|
| 8481 |
-
info="Higher quality takes more time to generate"
|
| 8482 |
-
)
|
| 8483 |
-
animation_video_input = gr.Video(
|
| 8484 |
-
label="Template video for animation (upload a video to use as motion template or character replacement source)",
|
| 8485 |
-
visible=False
|
| 8486 |
-
)
|
| 8487 |
-
|
| 8488 |
-
# LLM-guided media placement is now always on (no toggle in UI)
|
| 8489 |
-
|
| 8490 |
-
def on_image_to_image_toggle(toggled):
|
| 8491 |
-
vis = bool(toggled)
|
| 8492 |
-
return gr.update(visible=vis), gr.update(visible=vis)
|
| 8493 |
-
|
| 8494 |
-
def on_text_to_image_toggle(toggled):
|
| 8495 |
-
vis = bool(toggled)
|
| 8496 |
-
return gr.update(visible=vis)
|
| 8497 |
-
|
| 8498 |
-
image_to_image_toggle.change(
|
| 8499 |
-
on_image_to_image_toggle,
|
| 8500 |
-
inputs=[image_to_image_toggle],
|
| 8501 |
-
outputs=[generation_image_input, image_to_image_prompt]
|
| 8502 |
-
)
|
| 8503 |
-
def on_image_to_video_toggle(toggled):
|
| 8504 |
-
vis = bool(toggled)
|
| 8505 |
-
return gr.update(visible=vis), gr.update(visible=vis)
|
| 8506 |
-
|
| 8507 |
-
image_to_video_toggle.change(
|
| 8508 |
-
on_image_to_video_toggle,
|
| 8509 |
-
inputs=[image_to_video_toggle],
|
| 8510 |
-
outputs=[generation_image_input, image_to_video_prompt]
|
| 8511 |
-
)
|
| 8512 |
-
image_generation_toggle.change(
|
| 8513 |
-
on_text_to_image_toggle,
|
| 8514 |
-
inputs=[image_generation_toggle],
|
| 8515 |
-
outputs=[text_to_image_prompt]
|
| 8516 |
-
)
|
| 8517 |
-
text_to_video_toggle.change(
|
| 8518 |
-
on_text_to_image_toggle,
|
| 8519 |
-
inputs=[text_to_video_toggle],
|
| 8520 |
-
outputs=[text_to_video_prompt]
|
| 8521 |
-
)
|
| 8522 |
-
video_to_video_toggle.change(
|
| 8523 |
-
on_image_to_video_toggle,
|
| 8524 |
-
inputs=[video_to_video_toggle],
|
| 8525 |
-
outputs=[video_input, video_to_video_prompt]
|
| 8526 |
-
)
|
| 8527 |
-
text_to_music_toggle.change(
|
| 8528 |
-
on_text_to_image_toggle,
|
| 8529 |
-
inputs=[text_to_music_toggle],
|
| 8530 |
-
outputs=[text_to_music_prompt]
|
| 8531 |
-
)
|
| 8532 |
-
|
| 8533 |
-
def on_image_video_to_animation_toggle(toggled):
|
| 8534 |
-
vis = bool(toggled)
|
| 8535 |
-
return (
|
| 8536 |
-
gr.update(visible=vis), # generation_image_input
|
| 8537 |
-
gr.update(visible=vis), # animation_mode_dropdown
|
| 8538 |
-
gr.update(visible=vis), # animation_quality_dropdown
|
| 8539 |
-
gr.update(visible=vis), # animation_video_input
|
| 8540 |
-
)
|
| 8541 |
-
|
| 8542 |
-
image_video_to_animation_toggle.change(
|
| 8543 |
-
on_image_video_to_animation_toggle,
|
| 8544 |
-
inputs=[image_video_to_animation_toggle],
|
| 8545 |
-
outputs=[generation_image_input, animation_mode_dropdown, animation_quality_dropdown, animation_video_input]
|
| 8546 |
-
)
|
| 8547 |
model_dropdown = gr.Dropdown(
|
| 8548 |
choices=[model['name'] for model in AVAILABLE_MODELS],
|
| 8549 |
value=DEFAULT_MODEL_NAME,
|
|
@@ -8563,9 +7863,7 @@ with gr.Blocks(
|
|
| 8563 |
fn=lambda idx=i: gr.update(value=DEMO_LIST[idx]['description']),
|
| 8564 |
outputs=input
|
| 8565 |
)
|
| 8566 |
-
|
| 8567 |
-
gr.Markdown("⚠️ Web search unavailable", visible=True)
|
| 8568 |
-
# Remove model display and web search available line
|
| 8569 |
def on_model_change(model_name):
|
| 8570 |
for m in AVAILABLE_MODELS:
|
| 8571 |
if m['name'] == model_name:
|
|
@@ -9098,7 +8396,7 @@ with gr.Blocks(
|
|
| 9098 |
show_progress="hidden",
|
| 9099 |
).then(
|
| 9100 |
generation_code,
|
| 9101 |
-
inputs=[input, image_input,
|
| 9102 |
outputs=[code_output, history, sandbox, history_output]
|
| 9103 |
).then(
|
| 9104 |
end_generation_ui,
|
|
@@ -9139,7 +8437,7 @@ with gr.Blocks(
|
|
| 9139 |
show_progress="hidden",
|
| 9140 |
).then(
|
| 9141 |
generation_code,
|
| 9142 |
-
inputs=[input, image_input,
|
| 9143 |
outputs=[code_output, history, sandbox, history_output]
|
| 9144 |
).then(
|
| 9145 |
end_generation_ui,
|
|
|
|
| 23 |
|
| 24 |
import gradio as gr
|
| 25 |
from huggingface_hub import InferenceClient
|
|
|
|
| 26 |
from huggingface_hub import HfApi
|
| 27 |
import tempfile
|
| 28 |
from openai import OpenAI
|
|
|
|
| 1148 |
except Exception:
|
| 1149 |
return False
|
| 1150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1151 |
|
| 1152 |
# Stricter prompt for GLM-4.5V to ensure a complete, runnable HTML document with no escaped characters
|
| 1153 |
GLM45V_HTML_SYSTEM_PROMPT = """You are an expert front-end developer.
|
|
|
|
| 1377 |
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder
|
| 1378 |
"""
|
| 1379 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1380 |
|
| 1381 |
# Gradio system prompts will be dynamically populated by update_gradio_system_prompts()
|
| 1382 |
GRADIO_SYSTEM_PROMPT = ""
|
|
|
|
| 1396 |
|
| 1397 |
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder"""
|
| 1398 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1399 |
|
| 1400 |
# Multi-page static HTML project prompt (generic, production-style structure)
|
| 1401 |
MULTIPAGE_HTML_SYSTEM_PROMPT = """You are an expert front-end developer.
|
|
|
|
| 1436 |
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder
|
| 1437 |
"""
|
| 1438 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1439 |
|
| 1440 |
# Dynamic multi-page (model decides files) prompts
|
| 1441 |
DYNAMIC_MULTIPAGE_HTML_SYSTEM_PROMPT = """You are an expert front-end developer.
|
|
|
|
| 1469 |
IMPORTANT: Always include "Built with anycoder" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder
|
| 1470 |
"""
|
| 1471 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1472 |
|
|
|
|
| 1473 |
|
| 1474 |
# Follow-up system prompt for modifying existing HTML files
|
| 1475 |
FollowUpSystemPrompt = f"""You are an expert web developer modifying an existing project.
|
|
|
|
| 2107 |
Messages = List[Dict[str, str]]
|
| 2108 |
|
| 2109 |
# Tavily Search Client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2110 |
|
| 2111 |
def history_to_messages(history: History, system: str) -> Messages:
|
| 2112 |
messages = [{'role': 'system', 'content': system}]
|
|
|
|
| 3254 |
except Exception as e:
|
| 3255 |
print(f"[TempCleanup] Error during cleanup: {str(e)}")
|
| 3256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3257 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3258 |
|
| 3259 |
def generate_image_to_image(input_image_data, prompt: str, token: gr.OAuthToken | None = None) -> str:
|
| 3260 |
"""Generate an image using image-to-image via OpenRouter.
|
|
|
|
| 4661 |
print("[Video2Video] No <body> tag; appending video via replacement block")
|
| 4662 |
return f"{SEARCH_START}\n\n{DIVIDER}\n{video_html}\n{REPLACE_END}"
|
| 4663 |
|
| 4664 |
+
def apply_generated_media_to_html_REMOVED():
|
| 4665 |
"""Apply text/image/video/music replacements to HTML content.
|
| 4666 |
|
| 4667 |
- Works with single-document HTML strings
|
|
|
|
| 5171 |
# Updated for faster Tavily search and closer prompt usage
|
| 5172 |
# Uses 'advanced' search_depth and auto_parameters=True for speed and relevance
|
| 5173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5174 |
|
| 5175 |
def send_to_sandbox(code):
|
| 5176 |
"""Render HTML in a sandboxed iframe. Assumes full HTML is provided by prompts."""
|
|
|
|
| 5890 |
}
|
| 5891 |
|
| 5892 |
|
| 5893 |
+
def generation_code(query: str | None, vlm_image: Optional[gr.Image], file: str | None, website_url: str | None, _setting: Dict[str, str], _history: Optional[History], _current_model: Dict, language: str = "html", provider: str = "auto", profile: gr.OAuthProfile | None = None, token: gr.OAuthToken | None = None):
|
| 5894 |
# Check authentication first
|
| 5895 |
is_authenticated, auth_message = check_authentication(profile, token)
|
| 5896 |
if not is_authenticated:
|
|
|
|
| 6071 |
# Use language-specific prompt
|
| 6072 |
if language == "html":
|
| 6073 |
# Dynamic file selection always enabled
|
| 6074 |
+
system_prompt = DYNAMIC_MULTIPAGE_HTML_SYSTEM_PROMPT
|
| 6075 |
elif language == "transformers.js":
|
| 6076 |
+
system_prompt = TRANSFORMERS_JS_SYSTEM_PROMPT
|
| 6077 |
elif language == "svelte":
|
| 6078 |
+
system_prompt = SVELTE_SYSTEM_PROMPT
|
| 6079 |
elif language == "gradio":
|
| 6080 |
+
system_prompt = GRADIO_SYSTEM_PROMPT
|
| 6081 |
elif language == "json":
|
| 6082 |
+
system_prompt = JSON_SYSTEM_PROMPT
|
| 6083 |
else:
|
| 6084 |
+
system_prompt = GENERIC_SYSTEM_PROMPT.format(language=language)
|
| 6085 |
|
| 6086 |
messages = history_to_messages(_history, system_prompt)
|
| 6087 |
|
|
|
|
| 6113 |
This will help me create a better design for you."""
|
| 6114 |
query = f"{query}\n\n[Error extracting website: {website_text}]{fallback_guidance}"
|
| 6115 |
|
| 6116 |
+
# Use the original query without search enhancement
|
| 6117 |
+
enhanced_query = query
|
| 6118 |
|
| 6119 |
# Check if this is GLM-4.5 model and handle with simple HuggingFace InferenceClient
|
| 6120 |
if _current_model["id"] == "zai-org/GLM-4.5":
|
|
|
|
| 6161 |
|
| 6162 |
clean_code = remove_code_block(content)
|
| 6163 |
|
| 6164 |
+
# Use clean code as final content without media generation
|
| 6165 |
+
final_content = clean_code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6166 |
|
| 6167 |
_history.append([query, final_content])
|
| 6168 |
|
| 6169 |
if language == "transformers.js":
|
| 6170 |
files = parse_transformers_js_output(clean_code)
|
| 6171 |
if files['index.html'] and files['index.js'] and files['style.css']:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6172 |
formatted_output = format_transformers_js_output(files)
|
| 6173 |
yield {
|
| 6174 |
code_output: formatted_output,
|
|
|
|
| 6209 |
modified_content = apply_search_replace_changes(last_content, clean_code)
|
| 6210 |
clean_content = remove_code_block(modified_content)
|
| 6211 |
|
| 6212 |
+
# Use clean content without media generation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6213 |
|
| 6214 |
yield {
|
| 6215 |
code_output: clean_content,
|
|
|
|
| 6218 |
history_output: history_to_chatbot_messages(_history),
|
| 6219 |
}
|
| 6220 |
else:
|
| 6221 |
+
# Use clean code as final content without media generation
|
| 6222 |
+
final_content = clean_code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6223 |
|
| 6224 |
preview_val = None
|
| 6225 |
if language == "html":
|
|
|
|
| 6457 |
else:
|
| 6458 |
# Append content, filtering out placeholder thinking lines
|
| 6459 |
content += strip_placeholder_thinking(chunk_content)
|
| 6460 |
+
search_status = ""
|
| 6461 |
|
| 6462 |
# Handle transformers.js output differently
|
| 6463 |
if language == "transformers.js":
|
|
|
|
| 6636 |
modified_content = apply_search_replace_changes(last_content, final_code)
|
| 6637 |
clean_content = remove_code_block(modified_content)
|
| 6638 |
|
| 6639 |
+
# Use clean content without media generation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6640 |
|
| 6641 |
# Update history with the cleaned content
|
| 6642 |
_history.append([query, clean_content])
|
|
|
|
| 6650 |
# Regular generation - use the content as is
|
| 6651 |
final_content = remove_code_block(content)
|
| 6652 |
|
| 6653 |
+
# Use final content without media generation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6654 |
|
| 6655 |
_history.append([query, final_content])
|
| 6656 |
preview_val = None
|
|
|
|
| 7749 |
value=(
|
| 7750 |
"### Command Reference\n"
|
| 7751 |
"- **Language**: 'use streamlit' | 'use gradio' | 'use html'\n"
|
|
|
|
| 7752 |
"- **Model**: 'model <name>' (exact match to items in the Model dropdown)\n"
|
| 7753 |
"- **Website redesign**: include a URL in your message (e.g., 'https://example.com')\n"
|
| 7754 |
+
"- **Files**: attach documents or images directly for reference\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7755 |
"- **Multiple directives**: separate with commas. The first segment is the main build prompt.\n\n"
|
| 7756 |
"Examples:\n"
|
| 7757 |
+
"- anycoder coffee shop website\n"
|
| 7758 |
+
"- redesign https://example.com, use streamlit\n"
|
| 7759 |
+
"- dashboard ui with minimalist design"
|
| 7760 |
)
|
| 7761 |
)
|
| 7762 |
|
|
|
|
| 7814 |
label="UI design image",
|
| 7815 |
visible=False
|
| 7816 |
)
|
| 7817 |
+
# Removed image generation components
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7818 |
with gr.Row():
|
| 7819 |
btn = gr.Button("Generate", variant="secondary", size="lg", scale=2, visible=True, interactive=False)
|
| 7820 |
clear_btn = gr.Button("Clear", variant="secondary", size="sm", scale=1, visible=True)
|
| 7821 |
+
# --- Deploy/app name/sdk components ---
|
| 7822 |
space_name_input = gr.Textbox(
|
| 7823 |
label="app name (e.g. my-cool-app)",
|
| 7824 |
placeholder="Enter your app name",
|
|
|
|
| 7841 |
deploy_btn = gr.Button("🚀 Deploy App", variant="primary", visible=False)
|
| 7842 |
deploy_status = gr.Markdown(visible=False, label="Deploy status")
|
| 7843 |
# --- End move ---
|
| 7844 |
+
# Removed media generation and web search UI components
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7845 |
|
| 7846 |
+
# Removed media generation toggle event handlers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7847 |
model_dropdown = gr.Dropdown(
|
| 7848 |
choices=[model['name'] for model in AVAILABLE_MODELS],
|
| 7849 |
value=DEFAULT_MODEL_NAME,
|
|
|
|
| 7863 |
fn=lambda idx=i: gr.update(value=DEMO_LIST[idx]['description']),
|
| 7864 |
outputs=input
|
| 7865 |
)
|
| 7866 |
+
# Removed web search availability indicator
|
|
|
|
|
|
|
| 7867 |
def on_model_change(model_name):
|
| 7868 |
for m in AVAILABLE_MODELS:
|
| 7869 |
if m['name'] == model_name:
|
|
|
|
| 8396 |
show_progress="hidden",
|
| 8397 |
).then(
|
| 8398 |
generation_code,
|
| 8399 |
+
inputs=[input, image_input, file_input, website_url_input, setting, history, current_model, language_dropdown, provider_state],
|
| 8400 |
outputs=[code_output, history, sandbox, history_output]
|
| 8401 |
).then(
|
| 8402 |
end_generation_ui,
|
|
|
|
| 8437 |
show_progress="hidden",
|
| 8438 |
).then(
|
| 8439 |
generation_code,
|
| 8440 |
+
inputs=[input, image_input, file_input, website_url_input, setting, history, current_model, language_dropdown, provider_state],
|
| 8441 |
outputs=[code_output, history, sandbox, history_output]
|
| 8442 |
).then(
|
| 8443 |
end_generation_ui,
|
requirements.txt
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
git+https://github.com/huggingface/huggingface_hub.git
|
| 2 |
gradio[oauth]
|
| 3 |
-
tavily-python
|
| 4 |
PyPDF2
|
| 5 |
python-docx
|
| 6 |
pytesseract
|
|
|
|
| 1 |
git+https://github.com/huggingface/huggingface_hub.git
|
| 2 |
gradio[oauth]
|
|
|
|
| 3 |
PyPDF2
|
| 4 |
python-docx
|
| 5 |
pytesseract
|