Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,23 +3,21 @@ from huggingface_hub import InferenceClient
|
|
3 |
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
# Force the AI to generate a website with index.html and specified backend
|
9 |
-
forced_instruction = f"""
|
10 |
-
You must generate a complete website structure including at least an index.html.
|
11 |
-
Use the following backend structure: {backend}.
|
12 |
-
Only use {backend} relevant code and structure, and don't include any other type.
|
13 |
-
"""
|
14 |
-
system_message = forced_instruction + "\n\n" + system_message
|
15 |
|
16 |
messages = [{"role": "system", "content": system_message}]
|
17 |
-
for
|
18 |
-
if
|
19 |
-
messages.append({"role": "user", "content":
|
20 |
-
if
|
21 |
-
messages.append({"role": "assistant", "content":
|
22 |
-
|
23 |
messages.append({"role": "user", "content": message})
|
24 |
|
25 |
response = ""
|
@@ -31,22 +29,41 @@ Only use {backend} relevant code and structure, and don't include any other type
|
|
31 |
top_p=top_p,
|
32 |
):
|
33 |
token = message.choices[0].delta.content
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
gr.
|
43 |
-
gr.
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
if __name__ == "__main__":
|
52 |
demo.launch()
|
|
|
3 |
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
6 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p, backend):
|
7 |
+
forced_system = f"""
|
8 |
+
You are a code-generation AI. You MUST generate a full website including an index.html file.
|
9 |
+
Use only the {backend} backend structure.
|
10 |
+
Respond ONLY with raw code and file/folder structure. Do NOT explain or add commentary.
|
11 |
+
""".strip()
|
12 |
|
13 |
+
system_message = forced_system + "\n\n" + system_message
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
messages = [{"role": "system", "content": system_message}]
|
16 |
+
for user_msg, assistant_msg in history:
|
17 |
+
if user_msg:
|
18 |
+
messages.append({"role": "user", "content": user_msg})
|
19 |
+
if assistant_msg:
|
20 |
+
messages.append({"role": "assistant", "content": assistant_msg})
|
|
|
21 |
messages.append({"role": "user", "content": message})
|
22 |
|
23 |
response = ""
|
|
|
29 |
top_p=top_p,
|
30 |
):
|
31 |
token = message.choices[0].delta.content
|
32 |
+
if token:
|
33 |
+
response += token
|
34 |
+
yield response
|
35 |
+
|
36 |
+
with gr.Blocks() as demo:
|
37 |
+
gr.Markdown("# WebGen AI\nGenerate a complete website with your selected backend.")
|
38 |
+
|
39 |
+
with gr.Row():
|
40 |
+
system_msg = gr.Textbox(value="You're a helpful assistant.", label="System Message", lines=2)
|
41 |
+
backend = gr.Dropdown(["Flask", "Static", "Node.js"], value="Static", label="Backend")
|
42 |
+
|
43 |
+
with gr.Row():
|
44 |
+
max_tokens = gr.Slider(1, 2048, value=512, label="Max Tokens")
|
45 |
+
temperature = gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="Temperature")
|
46 |
+
top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p")
|
47 |
+
|
48 |
+
chatbot = gr.Chatbot()
|
49 |
+
msg = gr.Textbox(placeholder="Ask to generate a website...", label="Your Message")
|
50 |
+
|
51 |
+
def user_submit(message, chat_history):
|
52 |
+
return "", chat_history + [[message, None]]
|
53 |
+
|
54 |
+
submit = gr.Button("Send")
|
55 |
+
|
56 |
+
state = gr.State([])
|
57 |
+
|
58 |
+
submit.click(
|
59 |
+
user_submit,
|
60 |
+
[msg, state],
|
61 |
+
[msg, state]
|
62 |
+
).then(
|
63 |
+
respond,
|
64 |
+
[msg, state, system_msg, max_tokens, temperature, top_p, backend],
|
65 |
+
chatbot
|
66 |
+
)
|
67 |
|
68 |
if __name__ == "__main__":
|
69 |
demo.launch()
|