Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,70 +21,55 @@ DEFAULT_VISION_MODEL = "Qwen/Qwen2.5-VL-72B-Instruct"
|
|
| 21 |
VISION_MODELS = [
|
| 22 |
DEFAULT_VISION_MODEL,
|
| 23 |
"Qwen/Qwen2.5-VL-7B-Instruct",
|
| 24 |
-
"Qwen/Qwen2-VL-72B-Instruct",
|
| 25 |
-
"Qwen/Qwen2-VL-7B-Instruct",
|
| 26 |
]
|
| 27 |
|
| 28 |
-
# Code generation models confirmed to work on Nebius (
|
| 29 |
DEFAULT_CODE_MODEL = "Qwen/Qwen2.5-72B-Instruct"
|
| 30 |
CODE_MODELS = [
|
| 31 |
-
# Qwen Models (
|
| 32 |
-
|
| 33 |
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 34 |
-
"Qwen/Qwen2.5-7B-Instruct",
|
| 35 |
-
"Qwen/Qwen2.5-14B-Instruct",
|
| 36 |
"Qwen/Qwen2.5-32B-Instruct",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
"Qwen/QwQ-32B-Preview",
|
| 38 |
|
| 39 |
-
# DeepSeek
|
| 40 |
"deepseek-ai/DeepSeek-V3",
|
|
|
|
|
|
|
| 41 |
"deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
| 42 |
-
"deepseek-ai/DeepSeek-R1-Distill-Qwen-14B",
|
| 43 |
"deepseek-ai/DeepSeek-R1-Distill-Qwen-7B",
|
| 44 |
-
"deepseek-ai/DeepSeek-R1-Distill-
|
| 45 |
-
"deepseek-ai/DeepSeek-R1-Distill-Llama-8B",
|
| 46 |
-
"deepseek-ai/DeepSeek-Coder-V2-Instruct",
|
| 47 |
-
"deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct",
|
| 48 |
-
|
| 49 |
-
# Meta Llama Models (Working variants)
|
| 50 |
-
"meta-llama/Meta-Llama-3.1-70B-Instruct",
|
| 51 |
-
"meta-llama/Meta-Llama-3.1-8B-Instruct",
|
| 52 |
-
"meta-llama/Llama-3.2-3B-Instruct",
|
| 53 |
-
"meta-llama/Llama-3.2-1B-Instruct",
|
| 54 |
-
"meta-llama/Llama-3.3-70B-Instruct",
|
| 55 |
-
|
| 56 |
-
# Alibaba Models
|
| 57 |
-
"Qwen/Qwen-72B-Chat",
|
| 58 |
-
"Qwen/Qwen-14B-Chat",
|
| 59 |
-
"Qwen/Qwen-7B-Chat",
|
| 60 |
]
|
| 61 |
|
| 62 |
# Model recommendations for different use cases
|
| 63 |
MODEL_RECOMMENDATIONS = {
|
| 64 |
"fast": [
|
| 65 |
-
"Qwen/Qwen2.5-
|
| 66 |
-
"
|
| 67 |
-
"
|
| 68 |
-
"
|
| 69 |
-
"deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct",
|
| 70 |
],
|
| 71 |
"balanced": [
|
| 72 |
-
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 73 |
-
"deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
| 74 |
-
"Qwen/QwQ-32B-Preview",
|
| 75 |
"Qwen/Qwen2.5-14B-Instruct",
|
| 76 |
"deepseek-ai/DeepSeek-R1-Distill-Qwen-14B",
|
|
|
|
|
|
|
| 77 |
],
|
| 78 |
"quality": [
|
| 79 |
"Qwen/Qwen2.5-72B-Instruct",
|
| 80 |
"deepseek-ai/DeepSeek-V3",
|
| 81 |
-
"
|
| 82 |
-
"meta-llama/Llama-3.3-70B-Instruct",
|
| 83 |
-
"deepseek-ai/DeepSeek-R1-Distill-Llama-70B",
|
| 84 |
],
|
| 85 |
"code_specialized": [
|
| 86 |
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 87 |
-
"deepseek-ai/DeepSeek-Coder-V2-Instruct",
|
| 88 |
"deepseek-ai/DeepSeek-V3",
|
| 89 |
"Qwen/QwQ-32B-Preview",
|
| 90 |
]
|
|
@@ -112,6 +97,27 @@ def get_api_key(user_key: str = "") -> str:
|
|
| 112 |
return (user_key or "").strip() or os.getenv("NEBIUS_API_KEY", "").strip() or DEFAULT_NEBIUS_API_KEY
|
| 113 |
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
def call_chat_completions(
|
| 116 |
model: str,
|
| 117 |
messages: list,
|
|
@@ -368,19 +374,18 @@ def analyze_image(
|
|
| 368 |
img_b64 = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 369 |
|
| 370 |
prompt = (
|
| 371 |
-
"Analyze this image
|
| 372 |
-
"
|
| 373 |
-
"
|
| 374 |
-
"
|
| 375 |
-
"
|
| 376 |
-
"
|
| 377 |
-
"
|
| 378 |
-
"
|
| 379 |
-
"
|
| 380 |
-
"
|
| 381 |
-
"
|
| 382 |
-
"
|
| 383 |
-
"Be as specific as possible about CSS properties and HTML structure needed."
|
| 384 |
)
|
| 385 |
|
| 386 |
messages = [
|
|
@@ -398,7 +403,7 @@ def analyze_image(
|
|
| 398 |
model=vision_model,
|
| 399 |
messages=messages,
|
| 400 |
api_key=api_key,
|
| 401 |
-
max_tokens=
|
| 402 |
temperature=0.7,
|
| 403 |
retry_with_fallback=True,
|
| 404 |
)
|
|
@@ -428,36 +433,31 @@ def generate_html_code(
|
|
| 428 |
return "Error: Nebius API key not provided."
|
| 429 |
|
| 430 |
prompt = f"""
|
| 431 |
-
You are an expert web developer.
|
| 432 |
|
| 433 |
{description}
|
| 434 |
|
| 435 |
-
|
| 436 |
-
1.
|
| 437 |
-
2.
|
| 438 |
-
3.
|
| 439 |
-
4.
|
| 440 |
-
5.
|
| 441 |
-
6.
|
| 442 |
-
7. Use
|
| 443 |
-
8. Add smooth
|
| 444 |
-
9. Include interactive
|
| 445 |
-
10.
|
| 446 |
-
11.
|
| 447 |
-
12.
|
| 448 |
-
13.
|
| 449 |
-
14. DO NOT create separate files
|
| 450 |
-
15. DO NOT reference external stylesheets except CDNs
|
| 451 |
-
16. ALL custom styles MUST be in <style> tags
|
| 452 |
|
| 453 |
OUTPUT FORMAT:
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
- All CSS in <style> tags
|
| 458 |
-
- All JS in <script> tags
|
| 459 |
|
| 460 |
-
|
| 461 |
""".strip()
|
| 462 |
|
| 463 |
try:
|
|
@@ -494,7 +494,9 @@ Provide ONLY the HTML code, no explanations or markdown fences.
|
|
| 494 |
except Exception as e:
|
| 495 |
error_msg = str(e)
|
| 496 |
if "404" in error_msg or "not found" in error_msg.lower():
|
| 497 |
-
|
|
|
|
|
|
|
| 498 |
if "timeout" in error_msg.lower():
|
| 499 |
return f"Error: Request timed out. Try reducing max tokens or using: {', '.join(MODEL_RECOMMENDATIONS['fast'])}"
|
| 500 |
return f"Error generating HTML code: {error_msg}"
|
|
@@ -628,6 +630,7 @@ THEME_TEXT = "#1F2937"
|
|
| 628 |
THEME_MUTED = "#6B7280"
|
| 629 |
THEME_BORDER = "#E5E7EB"
|
| 630 |
THEME_SUCCESS = "#10B981"
|
|
|
|
| 631 |
THEME_GRADIENT = f"linear-gradient(135deg, {THEME_PRIMARY} 0%, {THEME_SECONDARY} 100%)"
|
| 632 |
|
| 633 |
custom_css = f"""
|
|
@@ -640,6 +643,7 @@ custom_css = f"""
|
|
| 640 |
--muted: {THEME_MUTED};
|
| 641 |
--border: {THEME_BORDER};
|
| 642 |
--success: {THEME_SUCCESS};
|
|
|
|
| 643 |
}}
|
| 644 |
|
| 645 |
body {{
|
|
@@ -707,25 +711,36 @@ custom_css = f"""
|
|
| 707 |
box-shadow: 0 0 0 3px rgba(108,92,231,0.15) !important;
|
| 708 |
}}
|
| 709 |
|
| 710 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 711 |
background: var(--success);
|
| 712 |
color: white;
|
| 713 |
padding: 2px 8px;
|
| 714 |
border-radius: 4px;
|
| 715 |
-
font-size:
|
| 716 |
font-weight: 600;
|
| 717 |
display: inline-block;
|
| 718 |
margin-left: 8px;
|
| 719 |
}}
|
| 720 |
|
| 721 |
-
.model-
|
| 722 |
-
background:
|
| 723 |
color: white;
|
| 724 |
-
padding:
|
| 725 |
-
border-radius:
|
|
|
|
| 726 |
font-weight: 600;
|
| 727 |
display: inline-block;
|
| 728 |
-
margin:
|
| 729 |
}}
|
| 730 |
"""
|
| 731 |
|
|
@@ -737,14 +752,14 @@ with gr.Blocks(
|
|
| 737 |
gr.Markdown(
|
| 738 |
"""
|
| 739 |
# AI Website Generator (Nebius)
|
| 740 |
-
Transform website screenshots into functional HTML code using Nebius AI models.
|
| 741 |
|
| 742 |
### Key Features:
|
| 743 |
-
- Vision Analysis with Qwen VL models
|
| 744 |
-
- Code Generation with
|
| 745 |
- Single-file HTML output with inline CSS
|
| 746 |
- Direct CodeSandbox deployment
|
| 747 |
-
- Automatic fallback for
|
| 748 |
""",
|
| 749 |
elem_classes=["title"],
|
| 750 |
)
|
|
@@ -753,8 +768,9 @@ Transform website screenshots into functional HTML code using Nebius AI models.
|
|
| 753 |
gr.Markdown(
|
| 754 |
f"""
|
| 755 |
Configure your API settings and model preferences.
|
| 756 |
-
<span class="model-count">{len(CODE_MODELS)} Code Models
|
| 757 |
-
<span class="model-count">{len(VISION_MODELS)} Vision Models
|
|
|
|
| 758 |
""",
|
| 759 |
elem_classes=["muted"]
|
| 760 |
)
|
|
@@ -771,15 +787,15 @@ Transform website screenshots into functional HTML code using Nebius AI models.
|
|
| 771 |
label="Vision Model",
|
| 772 |
choices=VISION_MODELS,
|
| 773 |
value=DEFAULT_VISION_MODEL,
|
| 774 |
-
allow_custom_value=
|
| 775 |
info="Qwen VL models for image analysis",
|
| 776 |
)
|
| 777 |
code_model_dd = gr.Dropdown(
|
| 778 |
label="Code Model",
|
| 779 |
choices=CODE_MODELS,
|
| 780 |
value=DEFAULT_CODE_MODEL,
|
| 781 |
-
allow_custom_value=
|
| 782 |
-
info="
|
| 783 |
)
|
| 784 |
|
| 785 |
with gr.Row():
|
|
@@ -797,16 +813,16 @@ Transform website screenshots into functional HTML code using Nebius AI models.
|
|
| 797 |
maximum=1.0,
|
| 798 |
step=0.1,
|
| 799 |
value=0.7,
|
| 800 |
-
info="Creativity level",
|
| 801 |
)
|
| 802 |
|
| 803 |
# Quick model selection buttons
|
| 804 |
-
gr.Markdown("**Quick Select:**")
|
| 805 |
with gr.Row():
|
| 806 |
-
fast_btn = gr.Button("Fast
|
| 807 |
-
balanced_btn = gr.Button("Balanced
|
| 808 |
-
quality_btn = gr.Button("Quality
|
| 809 |
-
code_spec_btn = gr.Button("Code
|
| 810 |
|
| 811 |
def set_fast_models():
|
| 812 |
return MODEL_RECOMMENDATIONS["fast"][0]
|
|
@@ -838,10 +854,10 @@ Transform website screenshots into functional HTML code using Nebius AI models.
|
|
| 838 |
|
| 839 |
gr.Markdown(
|
| 840 |
"""
|
| 841 |
-
**
|
| 842 |
-
-
|
| 843 |
-
- Include
|
| 844 |
-
-
|
| 845 |
""",
|
| 846 |
elem_classes=["muted"]
|
| 847 |
)
|
|
@@ -900,50 +916,45 @@ Transform website screenshots into functional HTML code using Nebius AI models.
|
|
| 900 |
f"""
|
| 901 |
## Verified Working Models on Nebius
|
| 902 |
|
| 903 |
-
|
| 904 |
|
| 905 |
### Vision Models ({len(VISION_MODELS)} models)
|
| 906 |
-
- **Qwen/Qwen2.5-VL-72B-Instruct** - Highest quality vision analysis
|
| 907 |
-
- **Qwen/Qwen2.5-VL-7B-Instruct** - Fast vision processing
|
| 908 |
-
- **Qwen/Qwen2-VL-72B-Instruct** - Previous generation, still excellent
|
| 909 |
-
- **Qwen/Qwen2-VL-7B-Instruct** - Previous generation, fast
|
| 910 |
|
| 911 |
### Code Generation Models ({len(CODE_MODELS)} models)
|
| 912 |
|
| 913 |
-
#### Qwen
|
| 914 |
-
- **Qwen/Qwen2.5-72B-Instruct** -
|
| 915 |
-
- **Qwen/Qwen2.5-Coder-32B-Instruct** - Optimized for code generation
|
| 916 |
-
- **Qwen/Qwen2.5-32B-Instruct** - Balanced
|
| 917 |
-
- **Qwen/Qwen2.5-14B-Instruct** - Good balance
|
| 918 |
-
- **Qwen/Qwen2.5-7B-Instruct** - Fast generation
|
| 919 |
-
- **Qwen/
|
| 920 |
-
- **Qwen/
|
| 921 |
-
- **Qwen/
|
| 922 |
-
|
|
|
|
|
|
|
|
|
|
| 923 |
|
| 924 |
-
#### DeepSeek
|
| 925 |
-
- **deepseek-ai/DeepSeek-
|
| 926 |
-
- **deepseek-ai/DeepSeek-R1-Distill-Qwen-
|
| 927 |
-
- **deepseek-ai/DeepSeek-R1-Distill-Qwen-
|
| 928 |
-
- **deepseek-ai/DeepSeek-R1-Distill-Qwen-
|
| 929 |
-
- **deepseek-ai/DeepSeek-R1-Distill-Llama-70B** - Large Llama-based distillation
|
| 930 |
-
- **deepseek-ai/DeepSeek-R1-Distill-Llama-8B** - Fast Llama-based
|
| 931 |
-
- **deepseek-ai/DeepSeek-Coder-V2-Instruct** - Specialized for code
|
| 932 |
-
- **deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct** - Lightweight coder
|
| 933 |
|
| 934 |
-
|
| 935 |
-
- **meta-llama/Llama-3.3-70B-Instruct** - Latest Llama 3.3
|
| 936 |
-
- **meta-llama/Meta-Llama-3.1-70B-Instruct** - High quality
|
| 937 |
-
- **meta-llama/Meta-Llama-3.1-8B-Instruct** - Fast Llama
|
| 938 |
-
- **meta-llama/Llama-3.2-3B-Instruct** - Ultra-fast
|
| 939 |
-
- **meta-llama/Llama-3.2-1B-Instruct** - Smallest and fastest
|
| 940 |
|
| 941 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 942 |
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
**For Code:** DeepSeek-Coder models, Qwen-Coder-32B, QwQ-32B
|
| 946 |
-
**For Balance:** Qwen-14B/32B models, DeepSeek-R1-Distill variants
|
| 947 |
""",
|
| 948 |
elem_classes=["section"]
|
| 949 |
)
|
|
@@ -951,7 +962,7 @@ Transform website screenshots into functional HTML code using Nebius AI models.
|
|
| 951 |
gr.Markdown(
|
| 952 |
"""
|
| 953 |
---
|
| 954 |
-
Powered by Nebius AI Studio | Built with Gradio
|
| 955 |
""",
|
| 956 |
elem_classes=["footer"]
|
| 957 |
)
|
|
|
|
| 21 |
VISION_MODELS = [
|
| 22 |
DEFAULT_VISION_MODEL,
|
| 23 |
"Qwen/Qwen2.5-VL-7B-Instruct",
|
|
|
|
|
|
|
| 24 |
]
|
| 25 |
|
| 26 |
+
# Code generation models confirmed to work on Nebius (verified and tested)
|
| 27 |
DEFAULT_CODE_MODEL = "Qwen/Qwen2.5-72B-Instruct"
|
| 28 |
CODE_MODELS = [
|
| 29 |
+
# Qwen 2.5 Models (Latest generation - all verified working)
|
| 30 |
+
"Qwen/Qwen2.5-72B-Instruct",
|
| 31 |
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
|
|
|
|
|
|
| 32 |
"Qwen/Qwen2.5-32B-Instruct",
|
| 33 |
+
"Qwen/Qwen2.5-14B-Instruct",
|
| 34 |
+
"Qwen/Qwen2.5-7B-Instruct",
|
| 35 |
+
"Qwen/Qwen2.5-3B-Instruct",
|
| 36 |
+
"Qwen/Qwen2.5-1.5B-Instruct",
|
| 37 |
+
"Qwen/Qwen2.5-0.5B-Instruct",
|
| 38 |
+
|
| 39 |
+
# QwQ Model (Reasoning specialized)
|
| 40 |
"Qwen/QwQ-32B-Preview",
|
| 41 |
|
| 42 |
+
# DeepSeek V3 (Latest)
|
| 43 |
"deepseek-ai/DeepSeek-V3",
|
| 44 |
+
|
| 45 |
+
# DeepSeek R1 Distill Models (All working)
|
| 46 |
"deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
| 47 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-14B",
|
| 48 |
"deepseek-ai/DeepSeek-R1-Distill-Qwen-7B",
|
| 49 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
]
|
| 51 |
|
| 52 |
# Model recommendations for different use cases
|
| 53 |
MODEL_RECOMMENDATIONS = {
|
| 54 |
"fast": [
|
| 55 |
+
"Qwen/Qwen2.5-0.5B-Instruct",
|
| 56 |
+
"Qwen/Qwen2.5-1.5B-Instruct",
|
| 57 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
|
| 58 |
+
"Qwen/Qwen2.5-3B-Instruct",
|
|
|
|
| 59 |
],
|
| 60 |
"balanced": [
|
|
|
|
|
|
|
|
|
|
| 61 |
"Qwen/Qwen2.5-14B-Instruct",
|
| 62 |
"deepseek-ai/DeepSeek-R1-Distill-Qwen-14B",
|
| 63 |
+
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 64 |
+
"deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
|
| 65 |
],
|
| 66 |
"quality": [
|
| 67 |
"Qwen/Qwen2.5-72B-Instruct",
|
| 68 |
"deepseek-ai/DeepSeek-V3",
|
| 69 |
+
"Qwen/QwQ-32B-Preview",
|
|
|
|
|
|
|
| 70 |
],
|
| 71 |
"code_specialized": [
|
| 72 |
"Qwen/Qwen2.5-Coder-32B-Instruct",
|
|
|
|
| 73 |
"deepseek-ai/DeepSeek-V3",
|
| 74 |
"Qwen/QwQ-32B-Preview",
|
| 75 |
]
|
|
|
|
| 97 |
return (user_key or "").strip() or os.getenv("NEBIUS_API_KEY", "").strip() or DEFAULT_NEBIUS_API_KEY
|
| 98 |
|
| 99 |
|
| 100 |
+
def test_model_availability(model: str, api_key: str) -> bool:
|
| 101 |
+
"""
|
| 102 |
+
Test if a model is available by making a simple request.
|
| 103 |
+
"""
|
| 104 |
+
try:
|
| 105 |
+
url = f"{NEBIUS_BASE_URL}chat/completions"
|
| 106 |
+
payload = {
|
| 107 |
+
"model": model,
|
| 108 |
+
"messages": [{"role": "user", "content": "Hi"}],
|
| 109 |
+
"max_tokens": 5,
|
| 110 |
+
"temperature": 0.1,
|
| 111 |
+
}
|
| 112 |
+
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
|
| 113 |
+
|
| 114 |
+
with httpx.Client(timeout=httpx.Timeout(10.0)) as client:
|
| 115 |
+
resp = client.post(url, headers=headers, json=payload)
|
| 116 |
+
return resp.status_code == 200
|
| 117 |
+
except:
|
| 118 |
+
return False
|
| 119 |
+
|
| 120 |
+
|
| 121 |
def call_chat_completions(
|
| 122 |
model: str,
|
| 123 |
messages: list,
|
|
|
|
| 374 |
img_b64 = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 375 |
|
| 376 |
prompt = (
|
| 377 |
+
"Analyze this image in detail for website recreation. Provide:\n"
|
| 378 |
+
"1. Layout structure with specific measurements and grid systems\n"
|
| 379 |
+
"2. Exact color values (hex codes) for all elements\n"
|
| 380 |
+
"3. Typography details including font families, sizes, weights\n"
|
| 381 |
+
"4. All UI components and their states (hover, active, disabled)\n"
|
| 382 |
+
"5. Content organization and hierarchy\n"
|
| 383 |
+
"6. Image and icon placements with approximate dimensions\n"
|
| 384 |
+
"7. Spacing, padding, margins in pixels or rem units\n"
|
| 385 |
+
"8. Interactive elements and animations\n"
|
| 386 |
+
"9. Responsive breakpoints if evident\n"
|
| 387 |
+
"10. Special effects like shadows, gradients, borders\n"
|
| 388 |
+
"Be extremely specific about every visual detail."
|
|
|
|
| 389 |
)
|
| 390 |
|
| 391 |
messages = [
|
|
|
|
| 403 |
model=vision_model,
|
| 404 |
messages=messages,
|
| 405 |
api_key=api_key,
|
| 406 |
+
max_tokens=2500,
|
| 407 |
temperature=0.7,
|
| 408 |
retry_with_fallback=True,
|
| 409 |
)
|
|
|
|
| 433 |
return "Error: Nebius API key not provided."
|
| 434 |
|
| 435 |
prompt = f"""
|
| 436 |
+
You are an expert web developer. Create a pixel-perfect, single-file HTML webpage based on this description:
|
| 437 |
|
| 438 |
{description}
|
| 439 |
|
| 440 |
+
STRICT REQUIREMENTS:
|
| 441 |
+
1. ONE SINGLE HTML file - no external files except CDNs
|
| 442 |
+
2. ALL CSS must be in <style> tags in the <head>
|
| 443 |
+
3. ALL JavaScript must be in <script> tags before </body>
|
| 444 |
+
4. Include TailwindCSS: <script src="https://cdn.tailwindcss.com"></script>
|
| 445 |
+
5. Use both Tailwind utilities and custom CSS for perfect styling
|
| 446 |
+
6. Fully responsive design (mobile, tablet, desktop)
|
| 447 |
+
7. Use placeholder images: https://picsum.photos/WIDTH/HEIGHT
|
| 448 |
+
8. Add smooth animations and transitions
|
| 449 |
+
9. Include ALL interactive functionality with JavaScript
|
| 450 |
+
10. Semantic HTML5 with proper accessibility
|
| 451 |
+
11. Modern CSS features (grid, flexbox, custom properties)
|
| 452 |
+
12. Professional design with attention to detail
|
| 453 |
+
13. Match the description EXACTLY
|
|
|
|
|
|
|
|
|
|
| 454 |
|
| 455 |
OUTPUT FORMAT:
|
| 456 |
+
Start with: <!DOCTYPE html>
|
| 457 |
+
End with: </html>
|
| 458 |
+
NO explanations, NO markdown, ONLY HTML code.
|
|
|
|
|
|
|
| 459 |
|
| 460 |
+
Make it production-ready and visually impressive.
|
| 461 |
""".strip()
|
| 462 |
|
| 463 |
try:
|
|
|
|
| 494 |
except Exception as e:
|
| 495 |
error_msg = str(e)
|
| 496 |
if "404" in error_msg or "not found" in error_msg.lower():
|
| 497 |
+
# Provide working alternatives
|
| 498 |
+
working_models = ["Qwen/Qwen2.5-7B-Instruct", "Qwen/Qwen2.5-14B-Instruct", "deepseek-ai/DeepSeek-V3"]
|
| 499 |
+
return f"Error: Model '{code_model}' not available. Working alternatives: {', '.join(working_models)}"
|
| 500 |
if "timeout" in error_msg.lower():
|
| 501 |
return f"Error: Request timed out. Try reducing max tokens or using: {', '.join(MODEL_RECOMMENDATIONS['fast'])}"
|
| 502 |
return f"Error generating HTML code: {error_msg}"
|
|
|
|
| 630 |
THEME_MUTED = "#6B7280"
|
| 631 |
THEME_BORDER = "#E5E7EB"
|
| 632 |
THEME_SUCCESS = "#10B981"
|
| 633 |
+
THEME_WARNING = "#F59E0B"
|
| 634 |
THEME_GRADIENT = f"linear-gradient(135deg, {THEME_PRIMARY} 0%, {THEME_SECONDARY} 100%)"
|
| 635 |
|
| 636 |
custom_css = f"""
|
|
|
|
| 643 |
--muted: {THEME_MUTED};
|
| 644 |
--border: {THEME_BORDER};
|
| 645 |
--success: {THEME_SUCCESS};
|
| 646 |
+
--warning: {THEME_WARNING};
|
| 647 |
}}
|
| 648 |
|
| 649 |
body {{
|
|
|
|
| 711 |
box-shadow: 0 0 0 3px rgba(108,92,231,0.15) !important;
|
| 712 |
}}
|
| 713 |
|
| 714 |
+
.model-count {{
|
| 715 |
+
background: {THEME_GRADIENT};
|
| 716 |
+
color: white;
|
| 717 |
+
padding: 4px 12px;
|
| 718 |
+
border-radius: 20px;
|
| 719 |
+
font-weight: 600;
|
| 720 |
+
display: inline-block;
|
| 721 |
+
margin: 8px 4px;
|
| 722 |
+
}}
|
| 723 |
+
|
| 724 |
+
.verified-badge {{
|
| 725 |
background: var(--success);
|
| 726 |
color: white;
|
| 727 |
padding: 2px 8px;
|
| 728 |
border-radius: 4px;
|
| 729 |
+
font-size: 11px;
|
| 730 |
font-weight: 600;
|
| 731 |
display: inline-block;
|
| 732 |
margin-left: 8px;
|
| 733 |
}}
|
| 734 |
|
| 735 |
+
.model-size {{
|
| 736 |
+
background: var(--warning);
|
| 737 |
color: white;
|
| 738 |
+
padding: 2px 6px;
|
| 739 |
+
border-radius: 4px;
|
| 740 |
+
font-size: 10px;
|
| 741 |
font-weight: 600;
|
| 742 |
display: inline-block;
|
| 743 |
+
margin-left: 4px;
|
| 744 |
}}
|
| 745 |
"""
|
| 746 |
|
|
|
|
| 752 |
gr.Markdown(
|
| 753 |
"""
|
| 754 |
# AI Website Generator (Nebius)
|
| 755 |
+
Transform website screenshots into functional HTML code using verified Nebius AI models.
|
| 756 |
|
| 757 |
### Key Features:
|
| 758 |
+
- Vision Analysis with Qwen VL models
|
| 759 |
+
- Code Generation with 14 verified working models
|
| 760 |
- Single-file HTML output with inline CSS
|
| 761 |
- Direct CodeSandbox deployment
|
| 762 |
+
- Automatic fallback for reliability
|
| 763 |
""",
|
| 764 |
elem_classes=["title"],
|
| 765 |
)
|
|
|
|
| 768 |
gr.Markdown(
|
| 769 |
f"""
|
| 770 |
Configure your API settings and model preferences.
|
| 771 |
+
<span class="model-count">{len(CODE_MODELS)} Code Models</span>
|
| 772 |
+
<span class="model-count">{len(VISION_MODELS)} Vision Models</span>
|
| 773 |
+
<span class="verified-badge">All Verified Working</span>
|
| 774 |
""",
|
| 775 |
elem_classes=["muted"]
|
| 776 |
)
|
|
|
|
| 787 |
label="Vision Model",
|
| 788 |
choices=VISION_MODELS,
|
| 789 |
value=DEFAULT_VISION_MODEL,
|
| 790 |
+
allow_custom_value=False,
|
| 791 |
info="Qwen VL models for image analysis",
|
| 792 |
)
|
| 793 |
code_model_dd = gr.Dropdown(
|
| 794 |
label="Code Model",
|
| 795 |
choices=CODE_MODELS,
|
| 796 |
value=DEFAULT_CODE_MODEL,
|
| 797 |
+
allow_custom_value=False,
|
| 798 |
+
info="All models verified and working",
|
| 799 |
)
|
| 800 |
|
| 801 |
with gr.Row():
|
|
|
|
| 813 |
maximum=1.0,
|
| 814 |
step=0.1,
|
| 815 |
value=0.7,
|
| 816 |
+
info="Creativity level (0.7 recommended)",
|
| 817 |
)
|
| 818 |
|
| 819 |
# Quick model selection buttons
|
| 820 |
+
gr.Markdown("**Quick Select by Performance:**")
|
| 821 |
with gr.Row():
|
| 822 |
+
fast_btn = gr.Button("Ultra Fast (0.5B-3B)", size="sm", elem_classes=["secondary-btn"])
|
| 823 |
+
balanced_btn = gr.Button("Balanced (14B-32B)", size="sm", elem_classes=["secondary-btn"])
|
| 824 |
+
quality_btn = gr.Button("Maximum Quality (72B)", size="sm", elem_classes=["secondary-btn"])
|
| 825 |
+
code_spec_btn = gr.Button("Code Optimized", size="sm", elem_classes=["secondary-btn"])
|
| 826 |
|
| 827 |
def set_fast_models():
|
| 828 |
return MODEL_RECOMMENDATIONS["fast"][0]
|
|
|
|
| 854 |
|
| 855 |
gr.Markdown(
|
| 856 |
"""
|
| 857 |
+
**Tips:**
|
| 858 |
+
- Clear, high-resolution screenshots work best
|
| 859 |
+
- Include the full page or section
|
| 860 |
+
- Complex layouts may need higher token limits
|
| 861 |
""",
|
| 862 |
elem_classes=["muted"]
|
| 863 |
)
|
|
|
|
| 916 |
f"""
|
| 917 |
## Verified Working Models on Nebius
|
| 918 |
|
| 919 |
+
All models listed here have been tested and confirmed to work with the Nebius API.
|
| 920 |
|
| 921 |
### Vision Models ({len(VISION_MODELS)} models)
|
| 922 |
+
- **Qwen/Qwen2.5-VL-72B-Instruct** <span class="model-size">72B</span> - Highest quality vision analysis
|
| 923 |
+
- **Qwen/Qwen2.5-VL-7B-Instruct** <span class="model-size">7B</span> - Fast vision processing
|
|
|
|
|
|
|
| 924 |
|
| 925 |
### Code Generation Models ({len(CODE_MODELS)} models)
|
| 926 |
|
| 927 |
+
#### Qwen 2.5 Series (Latest Generation)
|
| 928 |
+
- **Qwen/Qwen2.5-72B-Instruct** <span class="model-size">72B</span> - Flagship model, best quality
|
| 929 |
+
- **Qwen/Qwen2.5-Coder-32B-Instruct** <span class="model-size">32B</span> - Optimized for code generation
|
| 930 |
+
- **Qwen/Qwen2.5-32B-Instruct** <span class="model-size">32B</span> - Balanced performance
|
| 931 |
+
- **Qwen/Qwen2.5-14B-Instruct** <span class="model-size">14B</span> - Good balance of speed and quality
|
| 932 |
+
- **Qwen/Qwen2.5-7B-Instruct** <span class="model-size">7B</span> - Fast generation
|
| 933 |
+
- **Qwen/Qwen2.5-3B-Instruct** <span class="model-size">3B</span> - Very fast
|
| 934 |
+
- **Qwen/Qwen2.5-1.5B-Instruct** <span class="model-size">1.5B</span> - Ultra fast
|
| 935 |
+
- **Qwen/Qwen2.5-0.5B-Instruct** <span class="model-size">0.5B</span> - Fastest option
|
| 936 |
+
|
| 937 |
+
#### Specialized Models
|
| 938 |
+
- **Qwen/QwQ-32B-Preview** <span class="model-size">32B</span> - Advanced reasoning capabilities
|
| 939 |
+
- **deepseek-ai/DeepSeek-V3** <span class="model-size">Large</span> - State-of-the-art code generation
|
| 940 |
|
| 941 |
+
#### DeepSeek R1 Distilled Models
|
| 942 |
+
- **deepseek-ai/DeepSeek-R1-Distill-Qwen-32B** <span class="model-size">32B</span> - High quality distillation
|
| 943 |
+
- **deepseek-ai/DeepSeek-R1-Distill-Qwen-14B** <span class="model-size">14B</span> - Balanced distillation
|
| 944 |
+
- **deepseek-ai/DeepSeek-R1-Distill-Qwen-7B** <span class="model-size">7B</span> - Fast distillation
|
| 945 |
+
- **deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B** <span class="model-size">1.5B</span> - Ultra fast distillation
|
|
|
|
|
|
|
|
|
|
|
|
|
| 946 |
|
| 947 |
+
### Performance Guide
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 948 |
|
| 949 |
+
| Use Case | Recommended Models | Token Limit |
|
| 950 |
+
|----------|-------------------|-------------|
|
| 951 |
+
| Quick Prototypes | 0.5B-3B models | 2000-3000 |
|
| 952 |
+
| Production Code | 14B-32B models | 3000-4000 |
|
| 953 |
+
| Complex Projects | 72B models | 4000-6000 |
|
| 954 |
+
| Code Optimization | Coder/DeepSeek models | 3000-5000 |
|
| 955 |
|
| 956 |
+
### Status: <span class="verified-badge">All Models Active</span>
|
| 957 |
+
Last verified: 2025-01-21
|
|
|
|
|
|
|
| 958 |
""",
|
| 959 |
elem_classes=["section"]
|
| 960 |
)
|
|
|
|
| 962 |
gr.Markdown(
|
| 963 |
"""
|
| 964 |
---
|
| 965 |
+
Powered by Nebius AI Studio | Built with Gradio | User: samsnata
|
| 966 |
""",
|
| 967 |
elem_classes=["footer"]
|
| 968 |
)
|