File size: 2,713 Bytes
b358cdb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import gradio as gr
from utils import generate_website_code, preview_website

with gr.Blocks(theme=gr.themes.Soft(), title="AI Website Builder") as demo:
    gr.Markdown("""
    # 🤖 AI Website Builder
    Create stunning websites using powerful Hugging Face models. Preview your code in real-time!
    
    [Built with anycoder](https://huggingface.co/spaces/akhaliq/anycoder)
    """)
    
    with gr.Row():
        with gr.Column(scale=1):
            prompt = gr.Textbox(
                label="Describe your website",
                placeholder="E.g., 'A modern portfolio website for a photographer with a dark theme'",
                lines=3
            )
            
            model_choice = gr.Dropdown(
                choices=[
                    "OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5",
                    "Salesforce/codegen-350M-mono",
                    "Salesforce/codegen-2B-mono",
                    "bigcode/starcoder",
                    "meta-llama/Llama-2-70b-chat-hf",
                    "meta-llama/Llama-2-13b-chat-hf",
                    "mistralai/Mistral-7B-Instruct-v0.2",
                    "HuggingFaceH4/zephyr-7b-beta",
                    "google/gemma-7b-it",
                    "microsoft/Phi-3-mini-4k-instruct"
                ],
                value="Salesforce/codegen-2B-mono",
                label="Choose AI Model"
            )
            
            generate_btn = gr.Button("Generate Website", variant="primary")
            
        with gr.Column(scale=2):
            with gr.Tab("Code"):
                code_output = gr.Code(
                    label="Generated HTML/CSS/JS",
                    language="html",
                    interactive=True,
                    lines=20
                )
            with gr.Tab("Preview"):
                preview_output = gr.HTML(label="Website Preview")
                
    with gr.Row():
        with gr.Column():
            gr.Examples(
                examples=[
                    ["A simple landing page for a startup with a blue theme"],
                    ["A personal blog with a clean, minimalist design"],
                    ["An e-commerce product showcase page with cards"],
                    ["A restaurant menu with images and pricing"],
                ],
                inputs=[prompt]
            )
    
    generate_btn.click(
        generate_website_code,
        inputs=[prompt, model_choice],
        outputs=code_output
    ).then(
        preview_website,
        inputs=code_output,
        outputs=preview_output
    )
    
    code_output.change(
        preview_website,
        inputs=code_output,
        outputs=preview_output
    )

demo.launch()