My-AI-HTML-Gen / app.py
fenix577's picture
Update app.py
5b7d3f9 verified
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()