Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -241,7 +241,6 @@ def chat_complete(client, model: str, messages, timeout: int = 120) -> str:
|
|
| 241 |
except Exception as e:
|
| 242 |
return f"Error during model call: {e}"
|
| 243 |
|
| 244 |
-
|
| 245 |
def upload_file_to_mistral(
|
| 246 |
client,
|
| 247 |
path: str,
|
|
@@ -399,9 +398,8 @@ def process_media(src: str, custom_prompt: str, api_key: str, progress=gr.Progre
|
|
| 399 |
except Exception as e:
|
| 400 |
return f"Unable to determine media type or fetch file: {e}"
|
| 401 |
|
| 402 |
-
|
| 403 |
# ----------------------------------------------------------------------
|
| 404 |
-
# Gradio UI helpers
|
| 405 |
# ----------------------------------------------------------------------
|
| 406 |
css = ".preview_media img, .preview_media video { max-width: 100%; height: auto; }"
|
| 407 |
|
|
@@ -509,5 +507,46 @@ def create_demo():
|
|
| 509 |
def worker(url: str, prompt: str, key: str, progress=gr.Progress()):
|
| 510 |
return process_media(url or "", prompt or "", key or "", progress=progress)
|
| 511 |
|
| 512 |
-
def finish(result: str) -> tuple[str,
|
| 513 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
except Exception as e:
|
| 242 |
return f"Error during model call: {e}"
|
| 243 |
|
|
|
|
| 244 |
def upload_file_to_mistral(
|
| 245 |
client,
|
| 246 |
path: str,
|
|
|
|
| 398 |
except Exception as e:
|
| 399 |
return f"Unable to determine media type or fetch file: {e}"
|
| 400 |
|
|
|
|
| 401 |
# ----------------------------------------------------------------------
|
| 402 |
+
# Gradio UI helpers (continued/fixed)
|
| 403 |
# ----------------------------------------------------------------------
|
| 404 |
css = ".preview_media img, .preview_media video { max-width: 100%; height: auto; }"
|
| 405 |
|
|
|
|
| 507 |
def worker(url: str, prompt: str, key: str, progress=gr.Progress()):
|
| 508 |
return process_media(url or "", prompt or "", key or "", progress=progress)
|
| 509 |
|
| 510 |
+
def finish(result: str) -> tuple[str, dict]:
|
| 511 |
+
s = "done"
|
| 512 |
+
if not result:
|
| 513 |
+
md = "Error: no result returned."
|
| 514 |
+
s = "error"
|
| 515 |
+
elif isinstance(result, str) and result.lower().startswith("error"):
|
| 516 |
+
md = f"**Error:** {result}"
|
| 517 |
+
s = "error"
|
| 518 |
+
else:
|
| 519 |
+
md = result
|
| 520 |
+
|
| 521 |
+
return s, md
|
| 522 |
+
|
| 523 |
+
# Wire submit button: set status to busy, run worker, then finish
|
| 524 |
+
submit_btn.click(
|
| 525 |
+
fn=start_busy,
|
| 526 |
+
inputs=[],
|
| 527 |
+
outputs=[status, submit_btn],
|
| 528 |
+
)
|
| 529 |
+
|
| 530 |
+
submit_btn.click(
|
| 531 |
+
fn=worker,
|
| 532 |
+
inputs=[url_input, custom_prompt, api_key],
|
| 533 |
+
outputs=[final_md],
|
| 534 |
+
queue=True,
|
| 535 |
+
).then(
|
| 536 |
+
fn=finish,
|
| 537 |
+
inputs=[final_md],
|
| 538 |
+
outputs=[status, final_md],
|
| 539 |
+
)
|
| 540 |
+
|
| 541 |
+
# Update button label whenever status changes
|
| 542 |
+
def btn_label_for_state(s: str) -> str:
|
| 543 |
+
return _btn_label_for_status(s)
|
| 544 |
+
|
| 545 |
+
status.change(fn=btn_label_for_state, inputs=[status], outputs=[submit_btn])
|
| 546 |
+
|
| 547 |
+
return demo
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
if __name__ == "__main__":
|
| 551 |
+
demo = create_demo()
|
| 552 |
+
demo.launch(server_name="0.0.0.0", share=False)
|