parrotmaker commited on
Commit
18da24e
·
verified ·
1 Parent(s): 451af7e

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -62
app.py DELETED
@@ -1,62 +0,0 @@
1
- import gradio as gr
2
- from transformers import pipeline
3
- import zipfile
4
- import io
5
-
6
- assistant = pipeline("text-generation", model="Salesforce/codegen-350M-multi", max_new_tokens=512)
7
-
8
- def generate_code(prompt, html, css, js):
9
- result = assistant(f"# Task: {prompt}\n")[0]["generated_text"]
10
- new_html = html + "\n<!-- AI edit -->\n" + result
11
- return new_html, css, js
12
-
13
- def combine_code(html, css, js):
14
- return f"""<!DOCTYPE html><html><head><style>{css}</style></head><body>{html}<script>{js}</script></body></html>"""
15
-
16
- def export_zip(html, css, js):
17
- mem = io.BytesIO()
18
- with zipfile.ZipFile(mem, 'w') as zf:
19
- zf.writestr("index.html", f"<!DOCTYPE html><html><head><link rel='stylesheet' href='style.css'></head><body>{html}<script src='script.js'></script></body></html>")
20
- zf.writestr("style.css", css)
21
- zf.writestr("script.js", js)
22
- mem.seek(0)
23
- return (mem, "website.zip")
24
-
25
- with gr.Blocks() as demo:
26
- with gr.Row():
27
- # Left: AI Assistant
28
- with gr.Column(scale=1, min_width=250):
29
- gr.Markdown("### 🤖 Assistant")
30
- ai_chat_log = gr.Textbox(label="AI Output", lines=18, interactive=False)
31
- ai_input = gr.Textbox(label="Write what you want ✨")
32
- ai_button = gr.Button("Generate")
33
-
34
- # Right: Code Editor and Tools
35
- with gr.Column(scale=3):
36
- with gr.Row(equal_height=True):
37
- with gr.Row():
38
- html_tab = gr.Button("index.html")
39
- css_tab = gr.Button("styles.css")
40
- js_tab = gr.Button("script.js")
41
- plus_tab = gr.Button("+")
42
- with gr.Row():
43
- preview_button = gr.Button("▶️ Run")
44
- download_button = gr.Button("📦 Download")
45
- zip_file = gr.File(interactive=False)
46
-
47
- with gr.Tabs():
48
- with gr.Tab("HTML"):
49
- html_editor = gr.Code(language="html", label=None)
50
- with gr.Tab("CSS"):
51
- css_editor = gr.Code(language="css", label=None)
52
- with gr.Tab("JS"):
53
- js_editor = gr.Code(language="javascript", label=None)
54
- with gr.Tab("Preview"):
55
- live_preview = gr.HTML()
56
-
57
- # Logic hooks
58
- ai_button.click(generate_code, [ai_input, html_editor, css_editor, js_editor], [html_editor, css_editor, js_editor])
59
- preview_button.click(combine_code, [html_editor, css_editor, js_editor], live_preview)
60
- download_button.click(export_zip, [html_editor, css_editor, js_editor], zip_file)
61
-
62
- demo.launch()