Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,22 +3,17 @@ from huggingface_hub import InferenceClient
|
|
3 |
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
You are a code-generation AI. You MUST generate a full website including an index.html file.
|
9 |
-
Use
|
10 |
Respond ONLY with raw code and file/folder structure. Do NOT explain or add commentary.
|
11 |
-
""".strip()
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
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 = ""
|
24 |
for chunk in client.chat_completion(
|
@@ -26,7 +21,7 @@ Respond ONLY with raw code and file/folder structure. Do NOT explain or add comm
|
|
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:
|
@@ -34,46 +29,25 @@ Respond ONLY with raw code and file/folder structure. Do NOT explain or add comm
|
|
34 |
yield response
|
35 |
|
36 |
with gr.Blocks() as demo:
|
37 |
-
gr.Markdown("
|
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 |
-
|
45 |
-
|
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 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
|
58 |
-
|
59 |
|
60 |
-
|
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 |
-
|
70 |
-
|
71 |
-
inputs=[
|
72 |
-
outputs=
|
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__":
|
|
|
3 |
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
6 |
+
def generate_code(prompt, system_message, max_tokens, temperature, top_p, backend):
|
7 |
+
full_system_prompt = 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() + "\n\n" + system_message
|
12 |
|
13 |
+
messages = [
|
14 |
+
{"role": "system", "content": full_system_prompt},
|
15 |
+
{"role": "user", "content": prompt}
|
16 |
+
]
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
response = ""
|
19 |
for chunk in client.chat_completion(
|
|
|
21 |
max_tokens=max_tokens,
|
22 |
stream=True,
|
23 |
temperature=temperature,
|
24 |
+
top_p=top_p
|
25 |
):
|
26 |
token = chunk.choices[0].delta.content
|
27 |
if token:
|
|
|
29 |
yield response
|
30 |
|
31 |
with gr.Blocks() as demo:
|
32 |
+
gr.Markdown("## WebGen AI — One Prompt → Full Website Generator")
|
|
|
|
|
|
|
|
|
33 |
|
34 |
with gr.Row():
|
35 |
+
prompt = gr.Textbox(label="Enter Prompt", placeholder="Describe the website you want...")
|
36 |
+
backend = gr.Dropdown(["Flask", "Static", "Node.js"], value="Static", label="Select Backend")
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
+
system_msg = gr.Textbox(value="You are a helpful assistant.", label="System Message")
|
39 |
+
max_tokens = gr.Slider(1, 2048, value=512, label="Max Tokens")
|
40 |
+
temperature = gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="Temperature")
|
41 |
+
top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p")
|
42 |
|
43 |
+
code_output = gr.Code(label="AI Output (Live)", language="text")
|
44 |
|
45 |
+
run_btn = gr.Button("Generate Code")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
+
run_btn.click(
|
48 |
+
generate_code,
|
49 |
+
inputs=[prompt, system_msg, max_tokens, temperature, top_p, backend],
|
50 |
+
outputs=code_output
|
|
|
|
|
|
|
|
|
51 |
)
|
52 |
|
53 |
if __name__ == "__main__":
|