Commit
·
da6d09e
1
Parent(s):
9ab99d7
commit
Browse files
app.py
CHANGED
|
@@ -188,16 +188,25 @@ def extract_description(text):
|
|
| 188 |
return "Provides AI assistance for various tasks."
|
| 189 |
|
| 190 |
# Create the Gradio interface
|
| 191 |
-
with gr.Blocks(title="System Prompt Reformatter", theme=gr.themes.Soft()) as demo:
|
| 192 |
gr.HTML("<h1 style='text-align: center;'>System Prompt Reformatter</h1>")
|
| 193 |
gr.HTML("<p style='text-align: center;'>Transform system prompts to second person and make them ecosystem-agnostic</p>")
|
| 194 |
-
#
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
|
|
|
| 200 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
with gr.Tabs():
|
| 203 |
with gr.Tab("App"):
|
|
@@ -210,6 +219,7 @@ with gr.Blocks(title="System Prompt Reformatter", theme=gr.themes.Soft()) as dem
|
|
| 210 |
max_lines=20
|
| 211 |
)
|
| 212 |
submit_btn = gr.Button("Reformat Prompt", variant="primary")
|
|
|
|
| 213 |
|
| 214 |
with gr.Column(scale=1):
|
| 215 |
# Output order: Name -> Description -> System Prompt
|
|
@@ -222,26 +232,72 @@ with gr.Blocks(title="System Prompt Reformatter", theme=gr.themes.Soft()) as dem
|
|
| 222 |
description = gr.Textbox(
|
| 223 |
label="Description",
|
| 224 |
interactive=False,
|
| 225 |
-
show_copy_button=True
|
|
|
|
| 226 |
)
|
| 227 |
output_text = gr.Textbox(
|
| 228 |
label="Reformatted System Prompt",
|
| 229 |
lines=10,
|
| 230 |
max_lines=20,
|
| 231 |
interactive=False,
|
| 232 |
-
show_copy_button=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
)
|
|
|
|
| 234 |
|
| 235 |
# Wrapper to format outputs for UI ordering and bold name
|
| 236 |
def reformat_system_prompt_for_ui(input_text_val, api_key_val):
|
| 237 |
reformatted, name, desc = reformat_system_prompt(input_text_val, api_key_val)
|
| 238 |
name_md = f"**{name}**" if name else ""
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
submit_btn.click(
|
| 242 |
fn=reformat_system_prompt_for_ui,
|
| 243 |
inputs=[input_text, api_key],
|
| 244 |
-
outputs=[assistant_name_md, assistant_name_copy, description, output_text]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
)
|
| 246 |
|
| 247 |
# Add quick input example (fills the App input)
|
|
@@ -282,19 +338,20 @@ Copy buttons are available for all output fields.
|
|
| 282 |
|
| 283 |
with gr.Tab("Example"):
|
| 284 |
gr.Markdown("### End-to-End Example (voice-captured input)")
|
| 285 |
-
|
| 286 |
"I would like to create an AI assistant whose purpose is taking a list of different agents that I'll provide as a document, describing the list of agents and a short summary of the functionality of each. and it should return a document which suggests how they could be deployed into a multi-agent framework with specific patterns of delegation. In other words, it will take the list I provided and, if possible, identify the agent that could serve as the primary orchestrator, sub-orchestrators, and within under them, individual agents. It can present this information as it wishes, so long as the output is in readable markdown. That might take the format of basic diagrams showing the nesting, or it could use narrative or it could do both, but I'll provide the first and then it should return that as an output."
|
| 287 |
)
|
| 288 |
gr.Textbox(
|
| 289 |
label="Before",
|
| 290 |
-
value=
|
| 291 |
lines=10,
|
| 292 |
max_lines=20,
|
| 293 |
interactive=False,
|
| 294 |
show_copy_button=True,
|
|
|
|
| 295 |
)
|
| 296 |
|
| 297 |
-
|
| 298 |
"## NAME\n\n"
|
| 299 |
"Multi-Agent Framework Advisor\n\n"
|
| 300 |
"## DESCRIPTION\n\n"
|
|
@@ -305,12 +362,15 @@ Copy buttons are available for all output fields.
|
|
| 305 |
)
|
| 306 |
gr.Textbox(
|
| 307 |
label="After",
|
| 308 |
-
value=
|
| 309 |
lines=18,
|
| 310 |
max_lines=36,
|
| 311 |
interactive=False,
|
| 312 |
show_copy_button=True,
|
|
|
|
| 313 |
)
|
|
|
|
|
|
|
| 314 |
|
| 315 |
if __name__ == "__main__":
|
| 316 |
demo.launch()
|
|
|
|
| 188 |
return "Provides AI assistance for various tasks."
|
| 189 |
|
| 190 |
# Create the Gradio interface
|
| 191 |
+
with gr.Blocks(title="System Prompt Reformatter", theme=gr.themes.Soft(primary_hue="indigo", radius_size="lg")) as demo:
|
| 192 |
gr.HTML("<h1 style='text-align: center;'>System Prompt Reformatter</h1>")
|
| 193 |
gr.HTML("<p style='text-align: center;'>Transform system prompts to second person and make them ecosystem-agnostic</p>")
|
| 194 |
+
# Light monospace styling for text areas
|
| 195 |
+
gr.HTML(
|
| 196 |
+
"""
|
| 197 |
+
<style>
|
| 198 |
+
.monospace textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; line-height: 1.5; }
|
| 199 |
+
</style>
|
| 200 |
+
"""
|
| 201 |
)
|
| 202 |
+
# API key beneath subtitle within an Advanced accordion
|
| 203 |
+
with gr.Accordion("Advanced", open=False):
|
| 204 |
+
api_key = gr.Textbox(
|
| 205 |
+
label="OpenAI API Key (optional)",
|
| 206 |
+
placeholder="sk-... Leave blank to use offline reformatter",
|
| 207 |
+
type="password",
|
| 208 |
+
info="Tip: Set Space Secret OPENAI_API_KEY to avoid typing your key. The key is only used for this session."
|
| 209 |
+
)
|
| 210 |
|
| 211 |
with gr.Tabs():
|
| 212 |
with gr.Tab("App"):
|
|
|
|
| 219 |
max_lines=20
|
| 220 |
)
|
| 221 |
submit_btn = gr.Button("Reformat Prompt", variant="primary")
|
| 222 |
+
status_info = gr.Markdown(visible=False)
|
| 223 |
|
| 224 |
with gr.Column(scale=1):
|
| 225 |
# Output order: Name -> Description -> System Prompt
|
|
|
|
| 232 |
description = gr.Textbox(
|
| 233 |
label="Description",
|
| 234 |
interactive=False,
|
| 235 |
+
show_copy_button=True,
|
| 236 |
+
elem_classes=["monospace"],
|
| 237 |
)
|
| 238 |
output_text = gr.Textbox(
|
| 239 |
label="Reformatted System Prompt",
|
| 240 |
lines=10,
|
| 241 |
max_lines=20,
|
| 242 |
interactive=False,
|
| 243 |
+
show_copy_button=True,
|
| 244 |
+
elem_classes=["monospace"],
|
| 245 |
+
)
|
| 246 |
+
export_md = gr.Textbox(
|
| 247 |
+
label="Export (Markdown)",
|
| 248 |
+
lines=10,
|
| 249 |
+
max_lines=20,
|
| 250 |
+
interactive=False,
|
| 251 |
+
show_copy_button=True,
|
| 252 |
+
elem_classes=["monospace"],
|
| 253 |
+
)
|
| 254 |
+
export_json = gr.Textbox(
|
| 255 |
+
label="Export (JSON)",
|
| 256 |
+
lines=10,
|
| 257 |
+
max_lines=20,
|
| 258 |
+
interactive=False,
|
| 259 |
+
show_copy_button=True,
|
| 260 |
+
elem_classes=["monospace"],
|
| 261 |
)
|
| 262 |
+
clear_btn = gr.Button("Clear")
|
| 263 |
|
| 264 |
# Wrapper to format outputs for UI ordering and bold name
|
| 265 |
def reformat_system_prompt_for_ui(input_text_val, api_key_val):
|
| 266 |
reformatted, name, desc = reformat_system_prompt(input_text_val, api_key_val)
|
| 267 |
name_md = f"**{name}**" if name else ""
|
| 268 |
+
export_markdown = (
|
| 269 |
+
f"## NAME\n\n{name}\n\n"
|
| 270 |
+
f"## DESCRIPTION\n\n{desc}\n\n"
|
| 271 |
+
f"## SYSTEM PROMPT\n\n{reformatted}"
|
| 272 |
+
)
|
| 273 |
+
export_json_str = json.dumps({
|
| 274 |
+
"name": name,
|
| 275 |
+
"description": desc,
|
| 276 |
+
"reformatted": reformatted,
|
| 277 |
+
}, indent=2)
|
| 278 |
+
# Status: show offline note if no API key provided
|
| 279 |
+
using_key = bool((api_key_val or "").strip() or os.environ.get("OPENAI_API_KEY", "").strip())
|
| 280 |
+
status = gr.update(visible=not using_key, value=("Using offline reformatter (no API key provided)." if not using_key else ""))
|
| 281 |
+
return name_md, name, desc, reformatted, export_markdown, export_json_str, status
|
| 282 |
|
| 283 |
submit_btn.click(
|
| 284 |
fn=reformat_system_prompt_for_ui,
|
| 285 |
inputs=[input_text, api_key],
|
| 286 |
+
outputs=[assistant_name_md, assistant_name_copy, description, output_text, export_md, export_json, status_info]
|
| 287 |
+
)
|
| 288 |
+
# Submit on Enter
|
| 289 |
+
input_text.submit(
|
| 290 |
+
fn=reformat_system_prompt_for_ui,
|
| 291 |
+
inputs=[input_text, api_key],
|
| 292 |
+
outputs=[assistant_name_md, assistant_name_copy, description, output_text, export_md, export_json, status_info]
|
| 293 |
+
)
|
| 294 |
+
# Clear button resets input and outputs
|
| 295 |
+
def clear_all():
|
| 296 |
+
return "", "", "", "", "", "", "", gr.update(visible=False, value="")
|
| 297 |
+
clear_btn.click(
|
| 298 |
+
fn=clear_all,
|
| 299 |
+
inputs=None,
|
| 300 |
+
outputs=[input_text, assistant_name_md, assistant_name_copy, description, output_text, export_md, export_json, status_info]
|
| 301 |
)
|
| 302 |
|
| 303 |
# Add quick input example (fills the App input)
|
|
|
|
| 338 |
|
| 339 |
with gr.Tab("Example"):
|
| 340 |
gr.Markdown("### End-to-End Example (voice-captured input)")
|
| 341 |
+
example_before_text = (
|
| 342 |
"I would like to create an AI assistant whose purpose is taking a list of different agents that I'll provide as a document, describing the list of agents and a short summary of the functionality of each. and it should return a document which suggests how they could be deployed into a multi-agent framework with specific patterns of delegation. In other words, it will take the list I provided and, if possible, identify the agent that could serve as the primary orchestrator, sub-orchestrators, and within under them, individual agents. It can present this information as it wishes, so long as the output is in readable markdown. That might take the format of basic diagrams showing the nesting, or it could use narrative or it could do both, but I'll provide the first and then it should return that as an output."
|
| 343 |
)
|
| 344 |
gr.Textbox(
|
| 345 |
label="Before",
|
| 346 |
+
value=example_before_text,
|
| 347 |
lines=10,
|
| 348 |
max_lines=20,
|
| 349 |
interactive=False,
|
| 350 |
show_copy_button=True,
|
| 351 |
+
elem_classes=["monospace"],
|
| 352 |
)
|
| 353 |
|
| 354 |
+
example_after_text = (
|
| 355 |
"## NAME\n\n"
|
| 356 |
"Multi-Agent Framework Advisor\n\n"
|
| 357 |
"## DESCRIPTION\n\n"
|
|
|
|
| 362 |
)
|
| 363 |
gr.Textbox(
|
| 364 |
label="After",
|
| 365 |
+
value=example_after_text,
|
| 366 |
lines=18,
|
| 367 |
max_lines=36,
|
| 368 |
interactive=False,
|
| 369 |
show_copy_button=True,
|
| 370 |
+
elem_classes=["monospace"],
|
| 371 |
)
|
| 372 |
+
load_btn = gr.Button("Load 'Before' into App")
|
| 373 |
+
load_btn.click(lambda: example_before_text, inputs=None, outputs=input_text)
|
| 374 |
|
| 375 |
if __name__ == "__main__":
|
| 376 |
demo.launch()
|