Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,14 +2,14 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Модель для генерации кода (лёгкая, шустрая)
|
| 5 |
-
generator = pipeline("
|
| 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,
|
| 10 |
|
| 11 |
# Очистка кода
|
| 12 |
-
code = result
|
| 13 |
if not code.startswith('<!DOCTYPE'):
|
| 14 |
code = f"""<!DOCTYPE html>
|
| 15 |
<html lang="ru">
|
|
@@ -26,13 +26,10 @@ def generate_html(prompt):
|
|
| 26 |
return code
|
| 27 |
|
| 28 |
with gr.Blocks(title="My AI HTML Gen") as demo:
|
| 29 |
-
gr.Markdown("# 🎨
|
| 30 |
-
prompt = gr.Textbox(label="Промпт", placeholder="
|
| 31 |
btn = gr.Button("Генерировать! 🚀")
|
| 32 |
-
output = gr.Code(label="
|
| 33 |
-
|
| 34 |
-
gr.Examples(examples=[["landing page с hero"], ["кнопка с hover"], ["форма логина"], ["карточка товара"]], inputs=prompt)
|
| 35 |
-
|
| 36 |
btn.click(generate_html, prompt, output)
|
| 37 |
|
| 38 |
demo.launch()
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
# Модель для генерации кода (лёгкая, шустрая)
|
| 5 |
+
generator = pipeline("text2text-generation", model="microsoft/CodeT5-small")
|
| 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_length=800, num_return_sequences=1, temperature=0.3)
|
| 10 |
|
| 11 |
# Очистка кода
|
| 12 |
+
code = result[0]['generated_text'].strip()
|
| 13 |
if not code.startswith('<!DOCTYPE'):
|
| 14 |
code = f"""<!DOCTYPE html>
|
| 15 |
<html lang="ru">
|
|
|
|
| 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="Landing page", lines=2)
|
| 31 |
btn = gr.Button("Генерировать! 🚀")
|
| 32 |
+
output = gr.Code(label="HTML", language="html", lines=15, show_copy_button=True)
|
|
|
|
|
|
|
|
|
|
| 33 |
btn.click(generate_html, prompt, output)
|
| 34 |
|
| 35 |
demo.launch()
|