Commit
Β·
b5a3c55
1
Parent(s):
21ae2a3
commit
Browse files- app.py +144 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
from typing import Optional
|
4 |
+
|
5 |
+
# System prompt for reformatting rough drafts into polished system prompts
|
6 |
+
SYSTEM_PROMPT = """Your task is to assist the user by acting as a friendly assistant with the purpose of converting notes for AI assistants and reformatting them into polished, clear specifications for AI code generation agents and subagents. The text which the user will provide for your reformatting will be a rough draft describing the desired functionalities of the AI code generation agent which will likely fulfill the role of a sub-agent within a multi-agent framework focused on code generation or technical projects Upon receiving this rough draft your task is to reformat it into an improved and polished version defining a clear system prompt directing the agent in the second person you and ensuring that all of the user's desired functionalities are properly reflected in a better organised and clearer version of the system prompt intended to achieve the same deterministic behaviour as the user. as the user intended. Return this improved system prompt to the user in markdown within a code fence and without any other text. Assume each system prompt draft provided by the user to be intended as a new turn in the conversation - the previous agent specifications should not influence your generation of the next spec."""
|
7 |
+
|
8 |
+
# Initialize Hugging Face Inference Client
|
9 |
+
client = InferenceClient()
|
10 |
+
|
11 |
+
def reformat_prompt(rough_draft: str) -> str:
|
12 |
+
"""
|
13 |
+
Reformat a rough draft into a polished system prompt using Hugging Face free inference.
|
14 |
+
|
15 |
+
Args:
|
16 |
+
rough_draft: The rough draft text to be reformatted
|
17 |
+
|
18 |
+
Returns:
|
19 |
+
Reformatted system prompt or error message
|
20 |
+
"""
|
21 |
+
if not rough_draft.strip():
|
22 |
+
return "β Error: Please provide a rough draft to reformat."
|
23 |
+
|
24 |
+
try:
|
25 |
+
# Create the full prompt for the model
|
26 |
+
full_prompt = f"{SYSTEM_PROMPT}\n\nUser input to reformat:\n{rough_draft}"
|
27 |
+
|
28 |
+
# Use Hugging Face free inference with a capable model
|
29 |
+
response = client.text_generation(
|
30 |
+
prompt=full_prompt,
|
31 |
+
model="microsoft/DialoGPT-medium", # Free model good for text processing
|
32 |
+
max_new_tokens=1500,
|
33 |
+
temperature=0.1,
|
34 |
+
do_sample=True,
|
35 |
+
return_full_text=False
|
36 |
+
)
|
37 |
+
|
38 |
+
return response
|
39 |
+
|
40 |
+
except Exception as e:
|
41 |
+
# Fallback to a different model if the first one fails
|
42 |
+
try:
|
43 |
+
response = client.text_generation(
|
44 |
+
prompt=full_prompt,
|
45 |
+
model="HuggingFaceH4/zephyr-7b-beta",
|
46 |
+
max_new_tokens=1500,
|
47 |
+
temperature=0.1,
|
48 |
+
do_sample=True,
|
49 |
+
return_full_text=False
|
50 |
+
)
|
51 |
+
return response
|
52 |
+
except Exception as e2:
|
53 |
+
return f"β Error: Unable to process request. Please try again later. ({str(e2)})"
|
54 |
+
|
55 |
+
def create_interface():
|
56 |
+
"""Create and configure the Gradio interface."""
|
57 |
+
|
58 |
+
with gr.Blocks(
|
59 |
+
title="Code Gen Prompt Reformatter",
|
60 |
+
theme=gr.themes.Soft(),
|
61 |
+
css="""
|
62 |
+
.container {
|
63 |
+
max-width: 1200px;
|
64 |
+
margin: auto;
|
65 |
+
}
|
66 |
+
.header {
|
67 |
+
text-align: center;
|
68 |
+
margin-bottom: 2rem;
|
69 |
+
}
|
70 |
+
.api-key-box {
|
71 |
+
background-color: #f8f9fa;
|
72 |
+
padding: 1rem;
|
73 |
+
border-radius: 8px;
|
74 |
+
margin-bottom: 1rem;
|
75 |
+
}
|
76 |
+
"""
|
77 |
+
) as interface:
|
78 |
+
|
79 |
+
gr.HTML("""
|
80 |
+
<div class="header">
|
81 |
+
<h1>π Code Gen Prompt Reformatter</h1>
|
82 |
+
<p>Transform rough drafts into polished system prompts for AI code generation agents</p>
|
83 |
+
</div>
|
84 |
+
""")
|
85 |
+
|
86 |
+
with gr.Row():
|
87 |
+
with gr.Column():
|
88 |
+
rough_draft_input = gr.Textbox(
|
89 |
+
label="π Rough Draft",
|
90 |
+
placeholder="Enter your rough draft describing the desired functionalities of the AI code generation agent...",
|
91 |
+
lines=10,
|
92 |
+
max_lines=20
|
93 |
+
)
|
94 |
+
|
95 |
+
with gr.Row():
|
96 |
+
clear_btn = gr.Button("ποΈ Clear", variant="secondary")
|
97 |
+
submit_btn = gr.Button("β¨ Reformat Prompt", variant="primary", scale=2)
|
98 |
+
|
99 |
+
with gr.Column():
|
100 |
+
output = gr.Textbox(
|
101 |
+
label="π Reformatted System Prompt",
|
102 |
+
lines=15,
|
103 |
+
max_lines=25,
|
104 |
+
show_copy_button=True,
|
105 |
+
interactive=False
|
106 |
+
)
|
107 |
+
|
108 |
+
# Event handlers
|
109 |
+
submit_btn.click(
|
110 |
+
fn=reformat_prompt,
|
111 |
+
inputs=[rough_draft_input],
|
112 |
+
outputs=output,
|
113 |
+
show_progress=True
|
114 |
+
)
|
115 |
+
|
116 |
+
clear_btn.click(
|
117 |
+
fn=lambda: ("", ""),
|
118 |
+
outputs=[rough_draft_input, output]
|
119 |
+
)
|
120 |
+
|
121 |
+
# Example section
|
122 |
+
gr.HTML("""
|
123 |
+
<div style="margin-top: 2rem; padding: 1rem; background-color: #f0f8ff; border-radius: 8px;">
|
124 |
+
<h3>π‘ How to use:</h3>
|
125 |
+
<ol>
|
126 |
+
<li>Paste your rough draft describing the AI agent's desired functionalities</li>
|
127 |
+
<li>Click "Reformat Prompt" to get a polished system prompt</li>
|
128 |
+
<li>Copy the reformatted prompt for use in your multi-agent framework</li>
|
129 |
+
</ol>
|
130 |
+
<p><strong>Note:</strong> Each input is treated as a new turn - previous specifications won't influence the current generation.</p>
|
131 |
+
<p><strong>Powered by:</strong> Hugging Face free inference API - no API keys required!</p>
|
132 |
+
</div>
|
133 |
+
""")
|
134 |
+
|
135 |
+
return interface
|
136 |
+
|
137 |
+
# Create and launch the interface
|
138 |
+
if __name__ == "__main__":
|
139 |
+
app = create_interface()
|
140 |
+
app.launch(
|
141 |
+
server_name="0.0.0.0",
|
142 |
+
server_port=7860,
|
143 |
+
show_error=True
|
144 |
+
)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio==5.45.0
|
2 |
+
huggingface_hub
|