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 gradio as gr # 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): 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."""