Spaces:
Running
Running
remove website redesign
Browse files
app.py
CHANGED
|
@@ -1093,17 +1093,6 @@ def initialize_fastrtc_docs():
|
|
| 1093 |
# Configuration
|
| 1094 |
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
|
| 1095 |
|
| 1096 |
-
For website redesign tasks:
|
| 1097 |
-
- Use the provided original HTML code as the starting point for redesign
|
| 1098 |
-
- Preserve all original content, structure, and functionality
|
| 1099 |
-
- Keep the same semantic HTML structure but enhance the styling
|
| 1100 |
-
- Reuse all original images and their URLs from the HTML code
|
| 1101 |
-
- Create a modern, responsive design with improved typography and spacing
|
| 1102 |
-
- Use modern CSS frameworks and design patterns
|
| 1103 |
-
- Ensure accessibility and mobile responsiveness
|
| 1104 |
-
- Maintain the same navigation and user flow
|
| 1105 |
-
- Enhance the visual design while keeping the original layout structure
|
| 1106 |
-
|
| 1107 |
If an image is provided, analyze it and use the visual information to better understand the user's requirements.
|
| 1108 |
|
| 1109 |
Always respond with code that can be executed or rendered directly.
|
|
@@ -1902,10 +1891,6 @@ DEMO_LIST = [
|
|
| 1902 |
"title": "Extract Text from Image",
|
| 1903 |
"description": "Upload an image containing text and I'll extract and process the text content"
|
| 1904 |
},
|
| 1905 |
-
{
|
| 1906 |
-
"title": "Website Redesign",
|
| 1907 |
-
"description": "Enter a website URL to extract its content and redesign it with a modern, responsive layout"
|
| 1908 |
-
},
|
| 1909 |
{
|
| 1910 |
"title": "Modify HTML",
|
| 1911 |
"description": "After generating HTML, ask me to modify it with specific changes using search/replace format"
|
|
@@ -5447,339 +5432,6 @@ def demo_card_click(e: gr.EventData):
|
|
| 5447 |
# Return the first demo description as fallback
|
| 5448 |
return DEMO_LIST[0]['description']
|
| 5449 |
|
| 5450 |
-
def extract_website_content(url: str) -> str:
|
| 5451 |
-
"""Extract HTML code and content from a website URL"""
|
| 5452 |
-
try:
|
| 5453 |
-
# Validate URL
|
| 5454 |
-
parsed_url = urlparse(url)
|
| 5455 |
-
if not parsed_url.scheme:
|
| 5456 |
-
url = "https://" + url
|
| 5457 |
-
parsed_url = urlparse(url)
|
| 5458 |
-
|
| 5459 |
-
if not parsed_url.netloc:
|
| 5460 |
-
return "Error: Invalid URL provided"
|
| 5461 |
-
|
| 5462 |
-
# Set comprehensive headers to mimic a real browser request
|
| 5463 |
-
headers = {
|
| 5464 |
-
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
| 5465 |
-
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
|
| 5466 |
-
'Accept-Language': 'en-US,en;q=0.9',
|
| 5467 |
-
'Accept-Encoding': 'gzip, deflate, br',
|
| 5468 |
-
'DNT': '1',
|
| 5469 |
-
'Connection': 'keep-alive',
|
| 5470 |
-
'Upgrade-Insecure-Requests': '1',
|
| 5471 |
-
'Sec-Fetch-Dest': 'document',
|
| 5472 |
-
'Sec-Fetch-Mode': 'navigate',
|
| 5473 |
-
'Sec-Fetch-Site': 'none',
|
| 5474 |
-
'Sec-Fetch-User': '?1',
|
| 5475 |
-
'Cache-Control': 'max-age=0'
|
| 5476 |
-
}
|
| 5477 |
-
|
| 5478 |
-
# Create a session to maintain cookies and handle redirects
|
| 5479 |
-
session = requests.Session()
|
| 5480 |
-
session.headers.update(headers)
|
| 5481 |
-
|
| 5482 |
-
# Make the request with retry logic
|
| 5483 |
-
max_retries = 3
|
| 5484 |
-
for attempt in range(max_retries):
|
| 5485 |
-
try:
|
| 5486 |
-
response = session.get(url, timeout=15, allow_redirects=True)
|
| 5487 |
-
response.raise_for_status()
|
| 5488 |
-
break
|
| 5489 |
-
except requests.exceptions.HTTPError as e:
|
| 5490 |
-
if e.response.status_code == 403 and attempt < max_retries - 1:
|
| 5491 |
-
# Try with different User-Agent on 403
|
| 5492 |
-
session.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
| 5493 |
-
continue
|
| 5494 |
-
else:
|
| 5495 |
-
raise
|
| 5496 |
-
|
| 5497 |
-
# Get the raw HTML content with proper encoding
|
| 5498 |
-
try:
|
| 5499 |
-
# Try to get the content with automatic encoding detection
|
| 5500 |
-
response.encoding = response.apparent_encoding
|
| 5501 |
-
raw_html = response.text
|
| 5502 |
-
except:
|
| 5503 |
-
# Fallback to UTF-8 if encoding detection fails
|
| 5504 |
-
raw_html = response.content.decode('utf-8', errors='ignore')
|
| 5505 |
-
|
| 5506 |
-
# Debug: Check if we got valid HTML
|
| 5507 |
-
if not raw_html.strip().startswith('<!DOCTYPE') and not raw_html.strip().startswith('<html'):
|
| 5508 |
-
print(f"Warning: Response doesn't look like HTML. First 200 chars: {raw_html[:200]}")
|
| 5509 |
-
print(f"Response headers: {dict(response.headers)}")
|
| 5510 |
-
print(f"Response encoding: {response.encoding}")
|
| 5511 |
-
print(f"Apparent encoding: {response.apparent_encoding}")
|
| 5512 |
-
|
| 5513 |
-
# Try alternative approaches
|
| 5514 |
-
try:
|
| 5515 |
-
raw_html = response.content.decode('latin-1', errors='ignore')
|
| 5516 |
-
print("Tried latin-1 decoding")
|
| 5517 |
-
except:
|
| 5518 |
-
try:
|
| 5519 |
-
raw_html = response.content.decode('utf-8', errors='ignore')
|
| 5520 |
-
print("Tried UTF-8 decoding")
|
| 5521 |
-
except:
|
| 5522 |
-
raw_html = response.content.decode('cp1252', errors='ignore')
|
| 5523 |
-
print("Tried cp1252 decoding")
|
| 5524 |
-
|
| 5525 |
-
# Parse HTML content for analysis
|
| 5526 |
-
soup = BeautifulSoup(raw_html, 'html.parser')
|
| 5527 |
-
|
| 5528 |
-
# Check if this is a JavaScript-heavy site
|
| 5529 |
-
script_tags = soup.find_all('script')
|
| 5530 |
-
if len(script_tags) > 10:
|
| 5531 |
-
print(f"Warning: This site has {len(script_tags)} script tags - it may be a JavaScript-heavy site")
|
| 5532 |
-
print("The content might be loaded dynamically and not available in the initial HTML")
|
| 5533 |
-
|
| 5534 |
-
# Extract title
|
| 5535 |
-
title = soup.find('title')
|
| 5536 |
-
title_text = title.get_text().strip() if title else "No title found"
|
| 5537 |
-
|
| 5538 |
-
# Extract meta description
|
| 5539 |
-
meta_desc = soup.find('meta', attrs={'name': 'description'})
|
| 5540 |
-
description = meta_desc.get('content', '') if meta_desc else ""
|
| 5541 |
-
|
| 5542 |
-
# Extract main content areas for analysis
|
| 5543 |
-
content_sections = []
|
| 5544 |
-
main_selectors = [
|
| 5545 |
-
'main', 'article', '.content', '.main-content', '.post-content',
|
| 5546 |
-
'#content', '#main', '.entry-content', '.post-body'
|
| 5547 |
-
]
|
| 5548 |
-
|
| 5549 |
-
for selector in main_selectors:
|
| 5550 |
-
elements = soup.select(selector)
|
| 5551 |
-
for element in elements:
|
| 5552 |
-
text = element.get_text().strip()
|
| 5553 |
-
if len(text) > 100: # Only include substantial content
|
| 5554 |
-
content_sections.append(text)
|
| 5555 |
-
|
| 5556 |
-
# Extract navigation links for analysis
|
| 5557 |
-
nav_links = []
|
| 5558 |
-
nav_elements = soup.find_all(['nav', 'header'])
|
| 5559 |
-
for nav in nav_elements:
|
| 5560 |
-
links = nav.find_all('a')
|
| 5561 |
-
for link in links:
|
| 5562 |
-
link_text = link.get_text().strip()
|
| 5563 |
-
link_href = link.get('href', '')
|
| 5564 |
-
if link_text and link_href:
|
| 5565 |
-
nav_links.append(f"{link_text}: {link_href}")
|
| 5566 |
-
|
| 5567 |
-
# Extract and fix image URLs in the HTML
|
| 5568 |
-
img_elements = soup.find_all('img')
|
| 5569 |
-
for img in img_elements:
|
| 5570 |
-
src = img.get('src', '')
|
| 5571 |
-
if src:
|
| 5572 |
-
# Handle different URL formats
|
| 5573 |
-
if src.startswith('//'):
|
| 5574 |
-
# Protocol-relative URL
|
| 5575 |
-
absolute_src = 'https:' + src
|
| 5576 |
-
img['src'] = absolute_src
|
| 5577 |
-
elif src.startswith('/'):
|
| 5578 |
-
# Root-relative URL
|
| 5579 |
-
absolute_src = urljoin(url, src)
|
| 5580 |
-
img['src'] = absolute_src
|
| 5581 |
-
elif not src.startswith(('http://', 'https://')):
|
| 5582 |
-
# Relative URL
|
| 5583 |
-
absolute_src = urljoin(url, src)
|
| 5584 |
-
img['src'] = absolute_src
|
| 5585 |
-
# If it's already absolute, keep it as is
|
| 5586 |
-
|
| 5587 |
-
# Also check for data-src (lazy loading) and other common attributes
|
| 5588 |
-
data_src = img.get('data-src', '')
|
| 5589 |
-
if data_src and not src:
|
| 5590 |
-
# Use data-src if src is empty
|
| 5591 |
-
if data_src.startswith('//'):
|
| 5592 |
-
absolute_data_src = 'https:' + data_src
|
| 5593 |
-
img['src'] = absolute_data_src
|
| 5594 |
-
elif data_src.startswith('/'):
|
| 5595 |
-
absolute_data_src = urljoin(url, data_src)
|
| 5596 |
-
img['src'] = absolute_data_src
|
| 5597 |
-
elif not data_src.startswith(('http://', 'https://')):
|
| 5598 |
-
absolute_data_src = urljoin(url, data_src)
|
| 5599 |
-
img['src'] = absolute_data_src
|
| 5600 |
-
else:
|
| 5601 |
-
img['src'] = data_src
|
| 5602 |
-
|
| 5603 |
-
# Also fix background image URLs in style attributes
|
| 5604 |
-
elements_with_style = soup.find_all(attrs={'style': True})
|
| 5605 |
-
for element in elements_with_style:
|
| 5606 |
-
style_attr = element.get('style', '')
|
| 5607 |
-
# Find and replace relative URLs in background-image
|
| 5608 |
-
import re
|
| 5609 |
-
bg_pattern = r'background-image:\s*url\(["\']?([^"\']+)["\']?\)'
|
| 5610 |
-
matches = re.findall(bg_pattern, style_attr, re.IGNORECASE)
|
| 5611 |
-
for match in matches:
|
| 5612 |
-
if match:
|
| 5613 |
-
if match.startswith('//'):
|
| 5614 |
-
absolute_bg = 'https:' + match
|
| 5615 |
-
style_attr = style_attr.replace(match, absolute_bg)
|
| 5616 |
-
elif match.startswith('/'):
|
| 5617 |
-
absolute_bg = urljoin(url, match)
|
| 5618 |
-
style_attr = style_attr.replace(match, absolute_bg)
|
| 5619 |
-
elif not match.startswith(('http://', 'https://')):
|
| 5620 |
-
absolute_bg = urljoin(url, match)
|
| 5621 |
-
style_attr = style_attr.replace(match, absolute_bg)
|
| 5622 |
-
element['style'] = style_attr
|
| 5623 |
-
|
| 5624 |
-
# Fix background images in <style> tags
|
| 5625 |
-
style_elements = soup.find_all('style')
|
| 5626 |
-
for style in style_elements:
|
| 5627 |
-
if style.string:
|
| 5628 |
-
style_content = style.string
|
| 5629 |
-
# Find and replace relative URLs in background-image
|
| 5630 |
-
bg_pattern = r'background-image:\s*url\(["\']?([^"\']+)["\']?\)'
|
| 5631 |
-
matches = re.findall(bg_pattern, style_content, re.IGNORECASE)
|
| 5632 |
-
for match in matches:
|
| 5633 |
-
if match:
|
| 5634 |
-
if match.startswith('//'):
|
| 5635 |
-
absolute_bg = 'https:' + match
|
| 5636 |
-
style_content = style_content.replace(match, absolute_bg)
|
| 5637 |
-
elif match.startswith('/'):
|
| 5638 |
-
absolute_bg = urljoin(url, match)
|
| 5639 |
-
style_content = style_content.replace(match, absolute_bg)
|
| 5640 |
-
elif not match.startswith(('http://', 'https://')):
|
| 5641 |
-
absolute_bg = urljoin(url, match)
|
| 5642 |
-
style_content = style_content.replace(match, absolute_bg)
|
| 5643 |
-
style.string = style_content
|
| 5644 |
-
|
| 5645 |
-
# Extract images for analysis (after fixing URLs)
|
| 5646 |
-
images = []
|
| 5647 |
-
img_elements = soup.find_all('img')
|
| 5648 |
-
for img in img_elements:
|
| 5649 |
-
src = img.get('src', '')
|
| 5650 |
-
alt = img.get('alt', '')
|
| 5651 |
-
if src:
|
| 5652 |
-
images.append({'src': src, 'alt': alt})
|
| 5653 |
-
|
| 5654 |
-
# Debug: Print some image URLs to see what we're getting
|
| 5655 |
-
print(f"Found {len(images)} images:")
|
| 5656 |
-
for i, img in enumerate(images[:5]): # Show first 5 images
|
| 5657 |
-
print(f" {i+1}. {img['alt'] or 'No alt'} - {img['src']}")
|
| 5658 |
-
|
| 5659 |
-
# Test a few image URLs to see if they're accessible
|
| 5660 |
-
def test_image_url(img_url):
|
| 5661 |
-
try:
|
| 5662 |
-
test_response = requests.head(img_url, timeout=5, allow_redirects=True)
|
| 5663 |
-
return test_response.status_code == 200
|
| 5664 |
-
except:
|
| 5665 |
-
return False
|
| 5666 |
-
|
| 5667 |
-
# Test first few images
|
| 5668 |
-
working_images = []
|
| 5669 |
-
for img in images[:10]: # Test first 10 images
|
| 5670 |
-
if test_image_url(img['src']):
|
| 5671 |
-
working_images.append(img)
|
| 5672 |
-
else:
|
| 5673 |
-
print(f" ❌ Broken image: {img['src']}")
|
| 5674 |
-
|
| 5675 |
-
print(f"Working images: {len(working_images)} out of {len(images)}")
|
| 5676 |
-
|
| 5677 |
-
# Get the modified HTML with absolute URLs
|
| 5678 |
-
modified_html = str(soup)
|
| 5679 |
-
|
| 5680 |
-
# Clean and format the HTML for better readability
|
| 5681 |
-
# Remove unnecessary whitespace and comments
|
| 5682 |
-
import re
|
| 5683 |
-
cleaned_html = re.sub(r'<!--.*?-->', '', modified_html, flags=re.DOTALL) # Remove HTML comments
|
| 5684 |
-
cleaned_html = re.sub(r'\s+', ' ', cleaned_html) # Normalize whitespace
|
| 5685 |
-
cleaned_html = re.sub(r'>\s+<', '><', cleaned_html) # Remove whitespace between tags
|
| 5686 |
-
|
| 5687 |
-
# Limit HTML size to avoid token limits (keep first 15000 chars)
|
| 5688 |
-
if len(cleaned_html) > 15000:
|
| 5689 |
-
cleaned_html = cleaned_html[:15000] + "\n<!-- ... HTML truncated for length ... -->"
|
| 5690 |
-
|
| 5691 |
-
# Check if we got any meaningful content
|
| 5692 |
-
if not title_text or title_text == "No title found":
|
| 5693 |
-
title_text = url.split('/')[-1] or url.split('/')[-2] or "Website"
|
| 5694 |
-
|
| 5695 |
-
# If we couldn't extract any meaningful content, provide a fallback
|
| 5696 |
-
if len(cleaned_html.strip()) < 100:
|
| 5697 |
-
website_content = f"""
|
| 5698 |
-
WEBSITE REDESIGN - EXTRACTION FAILED
|
| 5699 |
-
====================================
|
| 5700 |
-
|
| 5701 |
-
URL: {url}
|
| 5702 |
-
Title: {title_text}
|
| 5703 |
-
|
| 5704 |
-
ERROR: Could not extract meaningful HTML content from this website. This could be due to:
|
| 5705 |
-
1. The website uses heavy JavaScript to load content dynamically
|
| 5706 |
-
2. The website has anti-bot protection
|
| 5707 |
-
3. The website requires authentication
|
| 5708 |
-
4. The website is using advanced compression or encoding
|
| 5709 |
-
|
| 5710 |
-
FALLBACK APPROACH:
|
| 5711 |
-
Please create a modern, responsive website design for a {title_text.lower()} website. Since I couldn't extract the original content, you can:
|
| 5712 |
-
|
| 5713 |
-
1. Create a typical layout for this type of website
|
| 5714 |
-
2. Use placeholder content that would be appropriate
|
| 5715 |
-
3. Include modern design elements and responsive features
|
| 5716 |
-
4. Use a clean, professional design with good typography
|
| 5717 |
-
5. Make it mobile-friendly and accessible
|
| 5718 |
-
|
| 5719 |
-
The website appears to be: {title_text}
|
| 5720 |
-
"""
|
| 5721 |
-
return website_content.strip()
|
| 5722 |
-
|
| 5723 |
-
# Compile the extracted content with the actual HTML code
|
| 5724 |
-
website_content = f"""
|
| 5725 |
-
WEBSITE REDESIGN - ORIGINAL HTML CODE
|
| 5726 |
-
=====================================
|
| 5727 |
-
|
| 5728 |
-
URL: {url}
|
| 5729 |
-
Title: {title_text}
|
| 5730 |
-
Description: {description}
|
| 5731 |
-
|
| 5732 |
-
PAGE ANALYSIS:
|
| 5733 |
-
- This appears to be a {title_text.lower()} website
|
| 5734 |
-
- Contains {len(content_sections)} main content sections
|
| 5735 |
-
- Has {len(nav_links)} navigation links
|
| 5736 |
-
- Includes {len(images)} images
|
| 5737 |
-
|
| 5738 |
-
IMAGES FOUND (use these exact URLs in your redesign):
|
| 5739 |
-
{chr(10).join([f"• {img['alt'] or 'Image'} - {img['src']}" for img in working_images[:20]]) if working_images else "No working images found"}
|
| 5740 |
-
|
| 5741 |
-
ALL IMAGES (including potentially broken ones):
|
| 5742 |
-
{chr(10).join([f"• {img['alt'] or 'Image'} - {img['src']}" for img in images[:20]]) if images else "No images found"}
|
| 5743 |
-
|
| 5744 |
-
ORIGINAL HTML CODE (use this as the base for redesign):
|
| 5745 |
-
```html
|
| 5746 |
-
{cleaned_html}
|
| 5747 |
-
```
|
| 5748 |
-
|
| 5749 |
-
REDESIGN INSTRUCTIONS:
|
| 5750 |
-
Please redesign this website with a modern, responsive layout while:
|
| 5751 |
-
1. Preserving all the original content and structure
|
| 5752 |
-
2. Maintaining the same navigation and functionality
|
| 5753 |
-
3. Using the original images and their URLs (listed above)
|
| 5754 |
-
4. Creating a modern, clean design with improved typography and spacing
|
| 5755 |
-
5. Making it fully responsive for mobile devices
|
| 5756 |
-
6. Using modern CSS frameworks and best practices
|
| 5757 |
-
7. Keeping the same semantic structure but with enhanced styling
|
| 5758 |
-
|
| 5759 |
-
IMPORTANT: All image URLs in the HTML code above have been converted to absolute URLs and are ready to use. Make sure to preserve these exact image URLs in your redesigned version.
|
| 5760 |
-
|
| 5761 |
-
The HTML code above contains the complete original website structure with all images properly linked. Use it as your starting point and create a modernized version.
|
| 5762 |
-
"""
|
| 5763 |
-
|
| 5764 |
-
return website_content.strip()
|
| 5765 |
-
|
| 5766 |
-
except requests.exceptions.HTTPError as e:
|
| 5767 |
-
if e.response.status_code == 403:
|
| 5768 |
-
return f"Error: Website blocked access (403 Forbidden). This website may have anti-bot protection. Try a different website or provide a description of what you want to build instead."
|
| 5769 |
-
elif e.response.status_code == 404:
|
| 5770 |
-
return f"Error: Website not found (404). Please check the URL and try again."
|
| 5771 |
-
elif e.response.status_code >= 500:
|
| 5772 |
-
return f"Error: Website server error ({e.response.status_code}). Please try again later."
|
| 5773 |
-
else:
|
| 5774 |
-
return f"Error accessing website: HTTP {e.response.status_code} - {str(e)}"
|
| 5775 |
-
except requests.exceptions.Timeout:
|
| 5776 |
-
return "Error: Request timed out. The website may be slow or unavailable."
|
| 5777 |
-
except requests.exceptions.ConnectionError:
|
| 5778 |
-
return "Error: Could not connect to the website. Please check your internet connection and the URL."
|
| 5779 |
-
except requests.exceptions.RequestException as e:
|
| 5780 |
-
return f"Error accessing website: {str(e)}"
|
| 5781 |
-
except Exception as e:
|
| 5782 |
-
return f"Error extracting website content: {str(e)}"
|
| 5783 |
|
| 5784 |
|
| 5785 |
stop_generation = False
|
|
@@ -5819,7 +5471,7 @@ def update_ui_for_auth_status(profile: gr.OAuthProfile | None = None, token: gr.
|
|
| 5819 |
}
|
| 5820 |
|
| 5821 |
|
| 5822 |
-
def generation_code(query: str | None, vlm_image: Optional[gr.Image],
|
| 5823 |
# Check authentication first
|
| 5824 |
is_authenticated, auth_message = check_authentication(profile, token)
|
| 5825 |
if not is_authenticated:
|
|
@@ -6008,25 +5660,6 @@ Generate the exact search/replace blocks needed to make these changes."""
|
|
| 6008 |
messages = history_to_messages(_history, system_prompt)
|
| 6009 |
|
| 6010 |
|
| 6011 |
-
# Extract website content and append to query if website URL is present
|
| 6012 |
-
website_text = ""
|
| 6013 |
-
if website_url and website_url.strip():
|
| 6014 |
-
website_text = extract_website_content(website_url.strip())
|
| 6015 |
-
if website_text and not website_text.startswith("Error"):
|
| 6016 |
-
website_text = website_text[:8000] # Limit to 8000 chars for prompt size
|
| 6017 |
-
query = f"{query}\n\n[Website content to redesign below]\n{website_text}"
|
| 6018 |
-
elif website_text.startswith("Error"):
|
| 6019 |
-
# Provide helpful guidance when website extraction fails
|
| 6020 |
-
fallback_guidance = """
|
| 6021 |
-
Since I couldn't extract the website content, please provide additional details about what you'd like to build:
|
| 6022 |
-
|
| 6023 |
-
1. What type of website is this? (e.g., e-commerce, blog, portfolio, dashboard)
|
| 6024 |
-
2. What are the main features you want?
|
| 6025 |
-
3. What's the target audience?
|
| 6026 |
-
4. Any specific design preferences? (colors, style, layout)
|
| 6027 |
-
|
| 6028 |
-
This will help me create a better design for you."""
|
| 6029 |
-
query = f"{query}\n\n[Error extracting website: {website_text}]{fallback_guidance}"
|
| 6030 |
|
| 6031 |
# Use the original query without search enhancement
|
| 6032 |
enhanced_query = query
|
|
@@ -7678,12 +7311,10 @@ with gr.Blocks(
|
|
| 7678 |
"### Command Reference\n"
|
| 7679 |
"- **Language**: 'use streamlit' | 'use gradio' | 'use html'\n"
|
| 7680 |
"- **Model**: 'model <name>' (exact match to items in the Model dropdown)\n"
|
| 7681 |
-
"- **Website redesign**: include a URL in your message (e.g., 'https://example.com')\n"
|
| 7682 |
"- **Files**: attach documents or images directly for reference\n"
|
| 7683 |
"- **Multiple directives**: separate with commas. The first segment is the main build prompt.\n\n"
|
| 7684 |
"Examples:\n"
|
| 7685 |
"- anycoder coffee shop website\n"
|
| 7686 |
-
"- redesign https://example.com, use streamlit\n"
|
| 7687 |
"- dashboard ui with minimalist design"
|
| 7688 |
)
|
| 7689 |
)
|
|
@@ -7727,12 +7358,6 @@ with gr.Blocks(
|
|
| 7727 |
label="Code Language",
|
| 7728 |
visible=True
|
| 7729 |
)
|
| 7730 |
-
website_url_input = gr.Textbox(
|
| 7731 |
-
label="website for redesign",
|
| 7732 |
-
placeholder="https://example.com",
|
| 7733 |
-
lines=1,
|
| 7734 |
-
visible=True
|
| 7735 |
-
)
|
| 7736 |
image_input = gr.Image(
|
| 7737 |
label="UI design image",
|
| 7738 |
visible=False
|
|
@@ -8275,7 +7900,7 @@ with gr.Blocks(
|
|
| 8275 |
show_progress="hidden",
|
| 8276 |
).then(
|
| 8277 |
generation_code,
|
| 8278 |
-
inputs=[input, image_input,
|
| 8279 |
outputs=[code_output, history, history_output]
|
| 8280 |
).then(
|
| 8281 |
end_generation_ui,
|
|
@@ -8316,7 +7941,7 @@ with gr.Blocks(
|
|
| 8316 |
show_progress="hidden",
|
| 8317 |
).then(
|
| 8318 |
generation_code,
|
| 8319 |
-
inputs=[input, image_input,
|
| 8320 |
outputs=[code_output, history, history_output]
|
| 8321 |
).then(
|
| 8322 |
end_generation_ui,
|
|
@@ -8359,7 +7984,7 @@ with gr.Blocks(
|
|
| 8359 |
|
| 8360 |
# Update deploy button text when space name changes
|
| 8361 |
space_name_input.change(update_deploy_button_text, inputs=[space_name_input], outputs=[deploy_btn])
|
| 8362 |
-
clear_btn.click(clear_history, outputs=[history, history_output
|
| 8363 |
clear_btn.click(hide_deploy_components, None, [space_name_input, deploy_btn])
|
| 8364 |
# Reset space name and button text when clearing
|
| 8365 |
clear_btn.click(
|
|
|
|
| 1093 |
# Configuration
|
| 1094 |
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
|
| 1095 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1096 |
If an image is provided, analyze it and use the visual information to better understand the user's requirements.
|
| 1097 |
|
| 1098 |
Always respond with code that can be executed or rendered directly.
|
|
|
|
| 1891 |
"title": "Extract Text from Image",
|
| 1892 |
"description": "Upload an image containing text and I'll extract and process the text content"
|
| 1893 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1894 |
{
|
| 1895 |
"title": "Modify HTML",
|
| 1896 |
"description": "After generating HTML, ask me to modify it with specific changes using search/replace format"
|
|
|
|
| 5432 |
# Return the first demo description as fallback
|
| 5433 |
return DEMO_LIST[0]['description']
|
| 5434 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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vlm_image: Optional[gr.Image], _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):
|
| 5475 |
# Check authentication first
|
| 5476 |
is_authenticated, auth_message = check_authentication(profile, token)
|
| 5477 |
if not is_authenticated:
|
|
|
|
| 5660 |
messages = history_to_messages(_history, system_prompt)
|
| 5661 |
|
| 5662 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5663 |
|
| 5664 |
# Use the original query without search enhancement
|
| 5665 |
enhanced_query = query
|
|
|
|
| 7311 |
"### Command Reference\n"
|
| 7312 |
"- **Language**: 'use streamlit' | 'use gradio' | 'use html'\n"
|
| 7313 |
"- **Model**: 'model <name>' (exact match to items in the Model dropdown)\n"
|
|
|
|
| 7314 |
"- **Files**: attach documents or images directly for reference\n"
|
| 7315 |
"- **Multiple directives**: separate with commas. The first segment is the main build prompt.\n\n"
|
| 7316 |
"Examples:\n"
|
| 7317 |
"- anycoder coffee shop website\n"
|
|
|
|
| 7318 |
"- dashboard ui with minimalist design"
|
| 7319 |
)
|
| 7320 |
)
|
|
|
|
| 7358 |
label="Code Language",
|
| 7359 |
visible=True
|
| 7360 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7361 |
image_input = gr.Image(
|
| 7362 |
label="UI design image",
|
| 7363 |
visible=False
|
|
|
|
| 7900 |
show_progress="hidden",
|
| 7901 |
).then(
|
| 7902 |
generation_code,
|
| 7903 |
+
inputs=[input, image_input, setting, history, current_model, language_dropdown, provider_state],
|
| 7904 |
outputs=[code_output, history, history_output]
|
| 7905 |
).then(
|
| 7906 |
end_generation_ui,
|
|
|
|
| 7941 |
show_progress="hidden",
|
| 7942 |
).then(
|
| 7943 |
generation_code,
|
| 7944 |
+
inputs=[input, image_input, setting, history, current_model, language_dropdown, provider_state],
|
| 7945 |
outputs=[code_output, history, history_output]
|
| 7946 |
).then(
|
| 7947 |
end_generation_ui,
|
|
|
|
| 7984 |
|
| 7985 |
# Update deploy button text when space name changes
|
| 7986 |
space_name_input.change(update_deploy_button_text, inputs=[space_name_input], outputs=[deploy_btn])
|
| 7987 |
+
clear_btn.click(clear_history, outputs=[history, history_output])
|
| 7988 |
clear_btn.click(hide_deploy_components, None, [space_name_input, deploy_btn])
|
| 7989 |
# Reset space name and button text when clearing
|
| 7990 |
clear_btn.click(
|