Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Модель для генерации кода (лёгкая, шустрая)
|
| 5 |
+
generator = pipeline("text-generation", model="microsoft/CodeT5-small", max_new_tokens=600, temperature=0.3)
|
| 6 |
+
|
| 7 |
+
def generate_html(prompt):
|
| 8 |
+
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."
|
| 9 |
+
result = generator(full_prompt, max_new_tokens=800)[0]['generated_text']
|
| 10 |
+
|
| 11 |
+
# Очистка кода
|
| 12 |
+
code = result.replace(full_prompt, '').strip()
|
| 13 |
+
if not code.startswith('<!DOCTYPE'):
|
| 14 |
+
code = f"""<!DOCTYPE html>
|
| 15 |
+
<html lang="ru">
|
| 16 |
+
<head>
|
| 17 |
+
<meta charset="UTF-8">
|
| 18 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 19 |
+
<title>{prompt}</title>
|
| 20 |
+
<style>{code}</style>
|
| 21 |
+
</head>
|
| 22 |
+
<body>
|
| 23 |
+
<!-- AI Generated HTML -->
|
| 24 |
+
</body>
|
| 25 |
+
</html>"""
|
| 26 |
+
return code
|
| 27 |
+
|
| 28 |
+
with gr.Blocks(title="My AI HTML Gen") as demo:
|
| 29 |
+
gr.Markdown("# 🎨 Мой AI Генератор HTML (Бесплатно!)")
|
| 30 |
+
prompt = gr.Textbox(label="Промпт", placeholder="Создай красивую кнопку с анимацией", lines=2)
|
| 31 |
+
btn = gr.Button("Генерировать! 🚀")
|
| 32 |
+
output = gr.Code(label="Готовый HTML", language="html", lines=20, show_copy_button=True)
|
| 33 |
+
|
| 34 |
+
gr.Examples(examples=[["landing page с hero"], ["кнопка с hover"], ["форма логина"], ["карточка товара"]], inputs=prompt)
|
| 35 |
+
|
| 36 |
+
btn.click(generate_html, prompt, output)
|
| 37 |
+
|
| 38 |
+
demo.launch()
|