fenix577 commited on
Commit
3f89339
·
verified ·
1 Parent(s): 032eb99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -2,14 +2,14 @@ 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">
@@ -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("# 🎨 Мой 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()
 
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()