Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ def respond(message, history, system_message, max_tokens, temperature, top_p, ba
|
|
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 |
-
|
12 |
|
13 |
system_message = forced_system + "\n\n" + system_message
|
14 |
|
@@ -21,14 +21,14 @@ Respond ONLY with raw code and file/folder structure. Do NOT explain or add comm
|
|
21 |
messages.append({"role": "user", "content": message})
|
22 |
|
23 |
response = ""
|
24 |
-
for
|
25 |
messages,
|
26 |
max_tokens=max_tokens,
|
27 |
stream=True,
|
28 |
temperature=temperature,
|
29 |
top_p=top_p,
|
30 |
):
|
31 |
-
token =
|
32 |
if token:
|
33 |
response += token
|
34 |
yield response
|
@@ -37,32 +37,43 @@ 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
|
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 |
-
|
|
|
|
|
50 |
|
51 |
-
def
|
52 |
-
|
|
|
|
|
53 |
|
54 |
-
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
[
|
61 |
-
[
|
62 |
).then(
|
63 |
-
|
64 |
-
[
|
65 |
-
chatbot
|
66 |
)
|
67 |
|
68 |
if __name__ == "__main__":
|
|
|
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 |
|
|
|
21 |
messages.append({"role": "user", "content": message})
|
22 |
|
23 |
response = ""
|
24 |
+
for chunk in client.chat_completion(
|
25 |
messages,
|
26 |
max_tokens=max_tokens,
|
27 |
stream=True,
|
28 |
temperature=temperature,
|
29 |
top_p=top_p,
|
30 |
):
|
31 |
+
token = chunk.choices[0].delta.content
|
32 |
if token:
|
33 |
response += token
|
34 |
yield response
|
|
|
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 are a helpful assistant.", label="System Message")
|
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 |
+
user_input = gr.Textbox(label="Your Prompt", placeholder="Ask the AI to generate a website...")
|
50 |
+
|
51 |
+
history = []
|
52 |
|
53 |
+
def chat_submit(message):
|
54 |
+
nonlocal history
|
55 |
+
history.append([message, None])
|
56 |
+
return "", history
|
57 |
|
58 |
+
send_btn = gr.Button("Send")
|
59 |
|
60 |
+
def run_response(message, system_msg, max_tokens, temperature, top_p, backend):
|
61 |
+
nonlocal history
|
62 |
+
response_generator = respond(message, history, system_msg, max_tokens, temperature, top_p, backend)
|
63 |
+
final_response = ""
|
64 |
+
for chunk in response_generator:
|
65 |
+
final_response = chunk
|
66 |
+
yield history[:-1] + [[message, chunk]]
|
67 |
+
history[-1][1] = final_response
|
68 |
|
69 |
+
send_btn.click(
|
70 |
+
chat_submit,
|
71 |
+
inputs=[user_input],
|
72 |
+
outputs=[user_input, chatbot]
|
73 |
).then(
|
74 |
+
run_response,
|
75 |
+
inputs=[user_input, system_msg, max_tokens, temperature, top_p, backend],
|
76 |
+
outputs=chatbot
|
77 |
)
|
78 |
|
79 |
if __name__ == "__main__":
|