Commit
·
31622fc
1
Parent(s):
2ace325
commit
Browse files
app.py
CHANGED
|
@@ -95,6 +95,25 @@ def reformat_prompt(api_key: str, rough_draft: str, prompt_type: str = "standard
|
|
| 95 |
def create_interface():
|
| 96 |
"""Create and configure the Gradio interface."""
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
with gr.Blocks(
|
| 99 |
title="Code Gen Agent Prompt Assistant",
|
| 100 |
theme=gr.themes.Soft(),
|
|
@@ -121,7 +140,16 @@ def create_interface():
|
|
| 121 |
white-space: pre-wrap;
|
| 122 |
border: 1px solid #dee2e6;
|
| 123 |
}
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
) as interface:
|
| 126 |
|
| 127 |
gr.HTML("""
|
|
@@ -139,9 +167,19 @@ def create_interface():
|
|
| 139 |
label="OpenAI API Key",
|
| 140 |
placeholder="sk-...",
|
| 141 |
type="password",
|
| 142 |
-
info="Your API key is
|
| 143 |
)
|
| 144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
prompt_type_radio = gr.Radio(
|
| 146 |
choices=[
|
| 147 |
("Standard Multi-Agent Prompt", "standard"),
|
|
@@ -233,6 +271,25 @@ def create_interface():
|
|
| 233 |
inputs=[api_key_input, rough_draft_input, prompt_type_radio],
|
| 234 |
outputs=output,
|
| 235 |
show_progress=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
)
|
| 237 |
|
| 238 |
clear_btn.click(
|
|
@@ -240,6 +297,14 @@ def create_interface():
|
|
| 240 |
outputs=[api_key_input, prompt_type_radio, rough_draft_input, output]
|
| 241 |
)
|
| 242 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
|
| 244 |
return interface
|
| 245 |
|
|
|
|
| 95 |
def create_interface():
|
| 96 |
"""Create and configure the Gradio interface."""
|
| 97 |
|
| 98 |
+
# JavaScript for localStorage API key persistence
|
| 99 |
+
js_code = """
|
| 100 |
+
function saveApiKey(api_key) {
|
| 101 |
+
if (api_key && api_key.trim()) {
|
| 102 |
+
localStorage.setItem('openai_api_key', api_key);
|
| 103 |
+
}
|
| 104 |
+
return api_key;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
function loadApiKey() {
|
| 108 |
+
return localStorage.getItem('openai_api_key') || '';
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
function clearApiKey() {
|
| 112 |
+
localStorage.removeItem('openai_api_key');
|
| 113 |
+
return '';
|
| 114 |
+
}
|
| 115 |
+
"""
|
| 116 |
+
|
| 117 |
with gr.Blocks(
|
| 118 |
title="Code Gen Agent Prompt Assistant",
|
| 119 |
theme=gr.themes.Soft(),
|
|
|
|
| 140 |
white-space: pre-wrap;
|
| 141 |
border: 1px solid #dee2e6;
|
| 142 |
}
|
| 143 |
+
.persistence-info {
|
| 144 |
+
background-color: #e8f5e8;
|
| 145 |
+
padding: 0.75rem;
|
| 146 |
+
border-radius: 6px;
|
| 147 |
+
margin-top: 0.5rem;
|
| 148 |
+
font-size: 0.9em;
|
| 149 |
+
color: #2d5a2d;
|
| 150 |
+
}
|
| 151 |
+
""",
|
| 152 |
+
js=js_code
|
| 153 |
) as interface:
|
| 154 |
|
| 155 |
gr.HTML("""
|
|
|
|
| 167 |
label="OpenAI API Key",
|
| 168 |
placeholder="sk-...",
|
| 169 |
type="password",
|
| 170 |
+
info="Your API key is stored locally in your browser and persists across sessions"
|
| 171 |
)
|
| 172 |
|
| 173 |
+
with gr.Row():
|
| 174 |
+
load_key_btn = gr.Button("Load Saved Key", variant="secondary", size="sm")
|
| 175 |
+
clear_key_btn = gr.Button("Clear Saved Key", variant="secondary", size="sm")
|
| 176 |
+
|
| 177 |
+
gr.HTML("""
|
| 178 |
+
<div class="persistence-info">
|
| 179 |
+
<strong>🔒 Privacy:</strong> Your API key is stored only in your browser's local storage and never sent to our servers.
|
| 180 |
+
</div>
|
| 181 |
+
""")
|
| 182 |
+
|
| 183 |
prompt_type_radio = gr.Radio(
|
| 184 |
choices=[
|
| 185 |
("Standard Multi-Agent Prompt", "standard"),
|
|
|
|
| 271 |
inputs=[api_key_input, rough_draft_input, prompt_type_radio],
|
| 272 |
outputs=output,
|
| 273 |
show_progress=True
|
| 274 |
+
).then(
|
| 275 |
+
fn=None,
|
| 276 |
+
inputs=[api_key_input],
|
| 277 |
+
outputs=None,
|
| 278 |
+
js="(api_key) => saveApiKey(api_key)"
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
load_key_btn.click(
|
| 282 |
+
fn=None,
|
| 283 |
+
inputs=None,
|
| 284 |
+
outputs=[api_key_input],
|
| 285 |
+
js="() => loadApiKey()"
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
+
clear_key_btn.click(
|
| 289 |
+
fn=None,
|
| 290 |
+
inputs=None,
|
| 291 |
+
outputs=[api_key_input],
|
| 292 |
+
js="() => clearApiKey()"
|
| 293 |
)
|
| 294 |
|
| 295 |
clear_btn.click(
|
|
|
|
| 297 |
outputs=[api_key_input, prompt_type_radio, rough_draft_input, output]
|
| 298 |
)
|
| 299 |
|
| 300 |
+
# Auto-load API key on interface load
|
| 301 |
+
interface.load(
|
| 302 |
+
fn=None,
|
| 303 |
+
inputs=None,
|
| 304 |
+
outputs=[api_key_input],
|
| 305 |
+
js="() => loadApiKey()"
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
|
| 309 |
return interface
|
| 310 |
|