Spaces:
Running
Running
cxumol
commited on
add Quick Config (JSON)
Browse files- app/app.py +32 -0
app/app.py
CHANGED
|
@@ -43,6 +43,15 @@ def init():
|
|
| 43 |
|
| 44 |
## Config Functions
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
def set_same_cheap_strong(
|
| 48 |
set_same: bool,
|
|
@@ -202,6 +211,11 @@ with gr.Blocks(
|
|
| 202 |
gr.Markdown(
|
| 203 |
"**CheapAI**, an honest format converter and refiner, extracts essential info from job description and résumé."
|
| 204 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
with gr.Group():
|
| 206 |
cheap_base = gr.Textbox(value=CHEAP_API_BASE, label="API Base")
|
| 207 |
cheap_key = gr.Textbox(
|
|
@@ -214,6 +228,11 @@ with gr.Blocks(
|
|
| 214 |
is_same_cheap_strong = gr.Checkbox(
|
| 215 |
label="the same as Cheap AI", value=False, container=False
|
| 216 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
with gr.Group():
|
| 218 |
strong_base = gr.Textbox(value=STRONG_API_BASE, label="API Base")
|
| 219 |
strong_key = gr.Textbox(
|
|
@@ -280,6 +299,19 @@ with gr.Blocks(
|
|
| 280 |
outputs=[setup_zone],
|
| 281 |
)
|
| 282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
infer_btn.click(
|
| 284 |
fn=set_same_cheap_strong,
|
| 285 |
inputs=[
|
|
|
|
| 43 |
|
| 44 |
## Config Functions
|
| 45 |
|
| 46 |
+
def apply_quick_config(config_json, target_base, target_key, target_model):
|
| 47 |
+
try:
|
| 48 |
+
config = json.loads(config_json)
|
| 49 |
+
updated_base = config.get("base", target_base)
|
| 50 |
+
updated_key = config.get("key", target_key)
|
| 51 |
+
updated_model = config.get("model", target_model)
|
| 52 |
+
return updated_base, updated_key, updated_model
|
| 53 |
+
except json.JSONDecodeError:
|
| 54 |
+
return target_base, target_key, target_model # Keep original values if JSON is invalid
|
| 55 |
|
| 56 |
def set_same_cheap_strong(
|
| 57 |
set_same: bool,
|
|
|
|
| 211 |
gr.Markdown(
|
| 212 |
"**CheapAI**, an honest format converter and refiner, extracts essential info from job description and résumé."
|
| 213 |
)
|
| 214 |
+
|
| 215 |
+
with gr.Row():
|
| 216 |
+
quick_config_cheapAI = gr.Textbox(label="Quick Config (JSON)")
|
| 217 |
+
apply_cheap_btn = gr.Button("Apply Quick Config", variant="secondary")
|
| 218 |
+
|
| 219 |
with gr.Group():
|
| 220 |
cheap_base = gr.Textbox(value=CHEAP_API_BASE, label="API Base")
|
| 221 |
cheap_key = gr.Textbox(
|
|
|
|
| 228 |
is_same_cheap_strong = gr.Checkbox(
|
| 229 |
label="the same as Cheap AI", value=False, container=False
|
| 230 |
)
|
| 231 |
+
|
| 232 |
+
with gr.Row():
|
| 233 |
+
quick_config_strongAI = gr.Textbox(label="Quick Config (JSON)")
|
| 234 |
+
apply_strong_btn = gr.Button("Apply Quick Config", variant="secondary")
|
| 235 |
+
|
| 236 |
with gr.Group():
|
| 237 |
strong_base = gr.Textbox(value=STRONG_API_BASE, label="API Base")
|
| 238 |
strong_key = gr.Textbox(
|
|
|
|
| 299 |
outputs=[setup_zone],
|
| 300 |
)
|
| 301 |
|
| 302 |
+
# apply_quick_config
|
| 303 |
+
apply_cheap_btn.click(
|
| 304 |
+
fn=apply_quick_config,
|
| 305 |
+
inputs=[quick_config_cheapAI, cheap_base, cheap_key, cheap_model],
|
| 306 |
+
outputs=[cheap_base, cheap_key, cheap_model],
|
| 307 |
+
)
|
| 308 |
+
|
| 309 |
+
apply_strong_btn.click(
|
| 310 |
+
fn=apply_quick_config,
|
| 311 |
+
inputs=[quick_config_strongAI, strong_base, strong_key, strong_model],
|
| 312 |
+
outputs=[strong_base, strong_key, strong_model],
|
| 313 |
+
)
|
| 314 |
+
|
| 315 |
infer_btn.click(
|
| 316 |
fn=set_same_cheap_strong,
|
| 317 |
inputs=[
|