Spaces:
Runtime error
Runtime error
File size: 1,312 Bytes
032eb99 5b7d3f9 3f89339 032eb99 3f89339 032eb99 5b7d3f9 3f89339 032eb99 5b7d3f9 3f89339 032eb99 3f89339 032eb99 | 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 | import gradio as gr
from transformers import pipeline
# Правильный pipeline для CodeT5-small
generator = pipeline("text2text-generation", model="microsoft/CodeT5-small")
def generate_html(prompt):
full_prompt = f"Generate full HTML code for: {prompt}. Include <!DOCTYPE html>, <html>, <head> with <style> and <script>, <body>. Make it responsive, beautiful, modern with CSS animations. Pure code only, no explanations."
result = generator(full_prompt, max_length=800, num_return_sequences=1, temperature=0.3)
# Очистка
code = result[0]['generated_text'].strip()
if not code.startswith('<!DOCTYPE'):
code = f"""<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{prompt}</title>
<style>{code}</style>
</head>
<body>
<!-- AI Generated HTML -->
</body>
</html>"""
return code
with gr.Blocks(title="My AI HTML Gen") as demo:
gr.Markdown("# 🎨 Твой AI HTML Генератор")
prompt = gr.Textbox(label="Промпт", placeholder="Landing page", lines=2)
btn = gr.Button("Генерировать! 🚀")
output = gr.Code(label="HTML", language="html", lines=15, show_copy_button=True)
btn.click(generate_html, prompt, output)
demo.launch() |