SandiyoS commited on
Commit
3f94ca7
·
verified ·
1 Parent(s): 752cac3

gradio: dict file_obj fix + queue + logging

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -594,7 +594,15 @@ with gradio_demo:
594
  if not prompt or not prompt.strip():
595
  raise gr.Error("prompt is required")
596
  tokens = DEFAULT_MAX_NEW_TOKENS if max_new_tokens is None else int(max_new_tokens)
597
- file_path = file_obj if isinstance(file_obj, str) else file_obj.name if hasattr(file_obj, 'name') else str(file_obj)
 
 
 
 
 
 
 
 
598
  try:
599
  with open(file_path, "rb") as f:
600
  data = f.read()
@@ -619,6 +627,7 @@ with gradio_demo:
619
  btn.click(gradio_solve, inputs=[inp_media, inp_prompt, inp_tokens], outputs=out_text, api_name="solve", concurrency_limit=None)
620
 
621
  # Advanced: URL/base64 juga didukung via API POST /solve (JSON), tidak perlu UI tambahan
 
622
 
623
  # ==================== RUN ====================
624
  if __name__ == "__main__":
 
594
  if not prompt or not prompt.strip():
595
  raise gr.Error("prompt is required")
596
  tokens = DEFAULT_MAX_NEW_TOKENS if max_new_tokens is None else int(max_new_tokens)
597
+ # gr.File di Gradio 5 bisa kirim str path atau dict {"path": "...", "_type": "gradio.FileData"}
598
+ if isinstance(file_obj, str):
599
+ file_path = file_obj
600
+ elif isinstance(file_obj, dict):
601
+ file_path = file_obj.get("path") or file_obj.get("name") or file_obj.get("url") or str(file_obj)
602
+ elif hasattr(file_obj, "name"):
603
+ file_path = file_obj.name
604
+ else:
605
+ file_path = str(file_obj)
606
  try:
607
  with open(file_path, "rb") as f:
608
  data = f.read()
 
627
  btn.click(gradio_solve, inputs=[inp_media, inp_prompt, inp_tokens], outputs=out_text, api_name="solve", concurrency_limit=None)
628
 
629
  # Advanced: URL/base64 juga didukung via API POST /solve (JSON), tidak perlu UI tambahan
630
+ gradio_demo.queue(max_size=20, default_concurrency_limit=1)
631
 
632
  # ==================== RUN ====================
633
  if __name__ == "__main__":