diff --git "a/app.py" "b/app.py"
--- "a/app.py"
+++ "b/app.py"
@@ -1,4339 +1,54 @@
-import os
-import re
-from http import HTTPStatus
-from typing import Dict, List, Optional, Tuple
-import base64
-import mimetypes
-import PyPDF2
-import docx
-import cv2
-import numpy as np
-from PIL import Image
-import pytesseract
-import requests
-from urllib.parse import urlparse, urljoin
-from bs4 import BeautifulSoup
-import html2text
-import json
-import time
-import webbrowser
-import urllib.parse
-import copy
-import html
-
+from app_huggingface import demo as demo_huggingface
+from app_gemini_coder import demo as demo_gemini
+from utils import get_app
import gradio as gr
-from huggingface_hub import InferenceClient
-from tavily import TavilyClient
-from huggingface_hub import HfApi
-import tempfile
-from openai import OpenAI
-from mistralai import Mistral
-
-# Gradio supported languages for syntax highlighting
-GRADIO_SUPPORTED_LANGUAGES = [
- "python", "c", "cpp", "markdown", "latex", "json", "html", "css", "javascript", "jinja2", "typescript", "yaml", "dockerfile", "shell", "r", "sql", "sql-msSQL", "sql-mySQL", "sql-mariaDB", "sql-sqlite", "sql-cassandra", "sql-plSQL", "sql-hive", "sql-pgSQL", "sql-gql", "sql-gpSQL", "sql-sparkSQL", "sql-esper", None
-]
-
-def get_gradio_language(language):
- # Map composite options to a supported syntax highlighting
- if language == "streamlit":
- return "python"
- if language == "gradio":
- return "python"
- return language if language in GRADIO_SUPPORTED_LANGUAGES else None
-
-# Search/Replace Constants
-SEARCH_START = "<<<<<<< SEARCH"
-DIVIDER = "======="
-REPLACE_END = ">>>>>>> REPLACE"
-
-# Configuration
-HTML_SYSTEM_PROMPT = """ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. MAKE IT RESPONSIVE USING MODERN CSS. Use as much as you can modern CSS for the styling, if you can't do something with modern CSS, then use custom CSS. Also, try to elaborate as much as you can, to create something unique. ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE
-
-For website redesign tasks:
-- Use the provided original HTML code as the starting point for redesign
-- Preserve all original content, structure, and functionality
-- Keep the same semantic HTML structure but enhance the styling
-- Reuse all original images and their URLs from the HTML code
-- Create a modern, responsive design with improved typography and spacing
-- Use modern CSS frameworks and design patterns
-- Ensure accessibility and mobile responsiveness
-- Maintain the same navigation and user flow
-- Enhance the visual design while keeping the original layout structure
-
-If an image is provided, analyze it and use the visual information to better understand the user's requirements.
-
-Always respond with code that can be executed or rendered directly.
-
-Always output only the HTML code inside a ```html ... ``` code block, and do not include any explanations or extra text. Do NOT add the language name at the top of the code output."""
-
-TRANSFORMERS_JS_SYSTEM_PROMPT = """You are an expert web developer creating a transformers.js application. You will generate THREE separate files: index.html, index.js, and style.css.
-
-IMPORTANT: You MUST output ALL THREE files in the following format:
-
-```html
-
-```
-
-```javascript
-// index.js content here
-```
-
-```css
-/* style.css content here */
-```
-
-Requirements:
-1. Create a modern, responsive web application using transformers.js
-2. Use the transformers.js library for AI/ML functionality
-3. Create a clean, professional UI with good user experience
-4. Make the application fully responsive for mobile devices
-5. Use modern CSS practices and JavaScript ES6+ features
-6. Include proper error handling and loading states
-7. Follow accessibility best practices
-
-The index.html should contain the basic HTML structure and link to the CSS and JS files.
-The index.js should contain all the JavaScript logic including transformers.js integration.
-The style.css should contain all the styling for the application.
-
-Always output only the three code blocks as shown above, and do not include any explanations or extra text."""
-
-SVELTE_SYSTEM_PROMPT = """You are an expert Svelte developer creating a modern Svelte application. You will generate ONLY the custom files that need user-specific content for the user's requested application.
-
-IMPORTANT: You MUST output files in the following format. Generate ONLY the files needed for the user's specific request:
-
-```svelte
-
-```
-
-```css
-/* src/app.css content here */
-```
-
-If you need additional components for the user's specific app, add them like:
-```svelte
-
-```
-
-Requirements:
-1. Create a modern, responsive Svelte application based on the user's specific request
-2. Use TypeScript for better type safety
-3. Create a clean, professional UI with good user experience
-4. Make the application fully responsive for mobile devices
-5. Use modern CSS practices and Svelte best practices
-6. Include proper error handling and loading states
-7. Follow accessibility best practices
-8. Use Svelte's reactive features effectively
-9. Include proper component structure and organization
-10. Generate ONLY components that are actually needed for the user's requested application
-
-Files you should generate:
-- src/App.svelte: Main application component (ALWAYS required)
-- src/app.css: Global styles (ALWAYS required)
-- src/lib/[ComponentName].svelte: Additional components (ONLY if needed for the user's specific app)
-
-The other files (index.html, package.json, vite.config.ts, tsconfig files, svelte.config.js, src/main.ts, src/vite-env.d.ts) are provided by the Svelte template and don't need to be generated.
-
-Always output only the two code blocks as shown above, and do not include any explanations or extra text."""
-
-SVELTE_SYSTEM_PROMPT_WITH_SEARCH = """You are an expert Svelte developer creating a modern Svelte application. You have access to real-time web search. When needed, use web search to find the latest information, best practices, or specific Svelte technologies.
-
-You will generate ONLY the custom files that need user-specific content.
-
-IMPORTANT: You MUST output ONLY the custom files in the following format:
-
-```svelte
-
-```
-
-```css
-/* src/app.css content here -->
-```
-
-Requirements:
-1. Create a modern, responsive Svelte application
-2. Use TypeScript for better type safety
-3. Create a clean, professional UI with good user experience
-4. Make the application fully responsive for mobile devices
-5. Use modern CSS practices and Svelte best practices
-6. Include proper error handling and loading states
-7. Follow accessibility best practices
-8. Use Svelte's reactive features effectively
-9. Include proper component structure and organization
-10. Use web search to find the latest Svelte patterns, libraries, and best practices
-
-The files you generate are:
-- src/App.svelte: Main application component (your custom app logic)
-- src/app.css: Global styles (your custom styling)
-
-The other files (index.html, package.json, vite.config.ts, tsconfig files, svelte.config.js, src/main.ts, src/vite-env.d.ts) are provided by the Svelte template and don't need to be generated.
-
-Always output only the two code blocks as shown above, and do not include any explanations or extra text."""
-
-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.
-
-You will generate THREE separate files: index.html, index.js, and style.css.
-
-IMPORTANT: You MUST output ALL THREE files in the following format:
-
-```html
-
-```
-
-```javascript
-// index.js content here
-```
-
-```css
-/* style.css content here */
-```
-
-Requirements:
-1. Create a modern, responsive web application using transformers.js
-2. Use the transformers.js library for AI/ML functionality
-3. Use web search to find current best practices and latest transformers.js features
-4. Create a clean, professional UI with good user experience
-5. Make the application fully responsive for mobile devices
-6. Use modern CSS practices and JavaScript ES6+ features
-7. Include proper error handling and loading states
-8. Follow accessibility best practices
-
-The index.html should contain the basic HTML structure and link to the CSS and JS files.
-The index.js should contain all the JavaScript logic including transformers.js integration.
-The style.css should contain all the styling for the application.
-
-Always output only the three code blocks as shown above, and do not include any explanations or extra text."""
-
-GENERIC_SYSTEM_PROMPT = """You are an expert {language} developer. Write clean, idiomatic, and runnable {language} code for the user's request. If possible, include comments and best practices. Output ONLY the code inside a ``` code block, and do not include any explanations or extra text. 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. Do NOT add the language name at the top of the code output."""
-
-# System prompt with search capability
-HTML_SYSTEM_PROMPT_WITH_SEARCH = """ONLY USE HTML, CSS AND JAVASCRIPT. If you want to use ICON make sure to import the library first. Try to create the best UI possible by using only HTML, CSS and JAVASCRIPT. MAKE IT RESPONSIVE USING MODERN CSS. Use as much as you can modern CSS for the styling, if you can't do something with modern CSS, then use custom CSS. Also, try to elaborate as much as you can, to create something unique. ALWAYS GIVE THE RESPONSE INTO A SINGLE HTML FILE
-
-You have access to real-time web search. When needed, use web search to find the latest information, best practices, or specific technologies.
-
-For website redesign tasks:
-- Use the provided original HTML code as the starting point for redesign
-- Preserve all original content, structure, and functionality
-- Keep the same semantic HTML structure but enhance the styling
-- Reuse all original images and their URLs from the HTML code
-- Use web search to find current design trends and best practices for the specific type of website
-- Create a modern, responsive design with improved typography and spacing
-- Use modern CSS frameworks and design patterns
-- Ensure accessibility and mobile responsiveness
-- Maintain the same navigation and user flow
-- Enhance the visual design while keeping the original layout structure
-
-If an image is provided, analyze it and use the visual information to better understand the user's requirements.
-
-Always respond with code that can be executed or rendered directly.
-
-Always output only the HTML code inside a ```html ... ``` code block, and do not include any explanations or extra text. Do NOT add the language name at the top of the code output."""
-
-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}.
-
-Write clean, idiomatic, and runnable {language} code for the user's request. If possible, include comments and best practices. Output ONLY the code inside a ``` code block, and do not include any explanations or extra text. 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. Do NOT add the language name at the top of the code output."""
-
-# Follow-up system prompt for modifying existing HTML files
-FollowUpSystemPrompt = f"""You are an expert web developer modifying an existing project.
-The user wants to apply changes based on their request.
-You MUST output ONLY the changes required using the following SEARCH/REPLACE block format. Do NOT output the entire file.
-Explain the changes briefly *before* the blocks if necessary, but the code changes THEMSELVES MUST be within the blocks.
-
-IMPORTANT: When the user reports an ERROR MESSAGE, analyze it carefully to determine which file needs fixing:
-- ImportError/ModuleNotFoundError → Fix requirements.txt by adding missing packages
-- Syntax errors in Python code → Fix app.py or the main Python file
-- HTML/CSS/JavaScript errors → Fix the respective HTML/CSS/JS files
-- Configuration errors → Fix config files, Docker files, etc.
-
-For Python applications (Gradio/Streamlit), the project structure typically includes:
-- app.py (main application file)
-- requirements.txt (dependencies)
-- Other supporting files as needed
-
-Format Rules:
-1. Start with {SEARCH_START}
-2. Provide the exact lines from the current code that need to be replaced.
-3. Use {DIVIDER} to separate the search block from the replacement.
-4. Provide the new lines that should replace the original lines.
-5. End with {REPLACE_END}
-6. You can use multiple SEARCH/REPLACE blocks if changes are needed in different parts of the file.
-7. To insert code, use an empty SEARCH block (only {SEARCH_START} and {DIVIDER} on their lines) if inserting at the very beginning, otherwise provide the line *before* the insertion point in the SEARCH block and include that line plus the new lines in the REPLACE block.
-8. To delete code, provide the lines to delete in the SEARCH block and leave the REPLACE block empty (only {DIVIDER} and {REPLACE_END} on their lines).
-9. IMPORTANT: The SEARCH block must *exactly* match the current code, including indentation and whitespace.
-10. For multi-file projects, specify which file you're modifying by starting with the filename before the search/replace block.
-
-Example Modifying Code:
-```
-Some explanation...
-{SEARCH_START}
-
Old Title
-{DIVIDER}
-
New Title
-{REPLACE_END}
-{SEARCH_START}
- ]*>", doc, flags=_re.IGNORECASE)
- if match:
- idx = match.end()
- doc = doc[:idx] + "\n" + style_tag + doc[idx:]
- else:
- # Append at beginning
- doc = style_tag + doc
-
- # Inline JS: insert before ', html_content.find(' str:
- """Create search/replace blocks that generate and insert ONLY ONE text-to-image result.
-
- Replaces the first detected placeholder; if none found, inserts one image near the top of .
- """
- if not prompt or not prompt.strip():
- return ""
-
- import re
-
- # Detect placeholders similarly to the multi-image version
- placeholder_patterns = [
- r']*src=["\'](?:placeholder|dummy|sample|example)[^"\']*["\'][^>]*>',
- r']*src=["\']https?://via\.placeholder\.com[^"\']*["\'][^>]*>',
- r']*src=["\']https?://picsum\.photos[^"\']*["\'][^>]*>',
- r']*src=["\']https?://dummyimage\.com[^"\']*["\'][^>]*>',
- r']*alt=["\'][^"\']*placeholder[^"\']*["\'][^>]*>',
- r']*class=["\'][^"\']*placeholder[^"\']*["\'][^>]*>',
- r']*id=["\'][^"\']*placeholder[^"\']*["\'][^>]*>',
- r']*src=["\']data:image[^"\']*["\'][^>]*>',
- r']*src=["\']#["\'][^>]*>',
- r']*src=["\']about:blank["\'][^>]*>',
- ]
-
- placeholder_images = []
- for pattern in placeholder_patterns:
- matches = re.findall(pattern, html_content, re.IGNORECASE)
- if matches:
- placeholder_images.extend(matches)
-
- # Fallback to any if no placeholders
- if not placeholder_images:
- img_pattern = r']*>'
- placeholder_images = re.findall(img_pattern, html_content)
-
- # Generate a single image
- image_html = generate_image_with_qwen(prompt, 0)
- if image_html.startswith("Error"):
- return ""
-
- # Replace first placeholder if present
- if placeholder_images:
- placeholder = placeholder_images[0]
- placeholder_clean = re.sub(r'\s+', ' ', placeholder.strip())
- placeholder_variations = [
- placeholder_clean,
- placeholder_clean.replace('"', "'"),
- placeholder_clean.replace("'", '"'),
- re.sub(r'\s+', ' ', placeholder_clean),
- placeholder_clean.replace(' ', ' '),
- ]
- blocks = []
- for variation in placeholder_variations:
- blocks.append(f"""{SEARCH_START}
-{variation}
-{DIVIDER}
-{image_html}
-{REPLACE_END}""")
- return '\n\n'.join(blocks)
-
- # Otherwise insert after
- if '', html_content.find(', just append
- return f"{SEARCH_START}\n\n{DIVIDER}\n{image_html}\n{REPLACE_END}"
-
-def create_image_replacement_blocks_from_input_image(html_content: str, user_prompt: str, input_image_data, max_images: int = 1) -> str:
- """Create search/replace blocks using image-to-image generation with a provided input image.
-
- Mirrors placeholder detection from create_image_replacement_blocks but uses generate_image_to_image.
- """
- if not user_prompt:
- return ""
- import re
-
- placeholder_patterns = [
- r']*src=["\'](?:placeholder|dummy|sample|example)[^"\']*["\'][^>]*>',
- r']*src=["\']https?://via\.placeholder\.com[^"\']*["\'][^>]*>',
- r']*src=["\']https?://picsum\.photos[^"\']*["\'][^>]*>',
- r']*src=["\']https?://dummyimage\.com[^"\']*["\'][^>]*>',
- r']*alt=["\'][^"\']*placeholder[^"\']*["\'][^>]*>',
- r']*class=["\'][^"\']*placeholder[^"\']*["\'][^>]*>',
- r']*id=["\'][^"\']*placeholder[^"\']*["\'][^>]*>',
- r']*src=["\']data:image[^"\']*["\'][^>]*>',
- r']*src=["\']#["\'][^>]*>',
- r']*src=["\']about:blank["\'][^>]*>',
- ]
-
- placeholder_images = []
- for pattern in placeholder_patterns:
- matches = re.findall(pattern, html_content, re.IGNORECASE)
- placeholder_images.extend(matches)
-
- if not placeholder_images:
- img_pattern = r']*>'
- placeholder_images = re.findall(img_pattern, html_content)
-
- div_placeholder_patterns = [
- r'