felixkky commited on
Commit
bb5a8cf
·
verified ·
1 Parent(s): 5213eea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -1
app.py CHANGED
@@ -24,6 +24,11 @@ setup_omr_checker()
24
 
25
  def process_omr_api(image_base64, template_json_str):
26
  logger.info("收到 OMR 請求")
 
 
 
 
 
27
  try:
28
  # 建立工作目錄
29
  job_dir = os.path.join(OMR_DIR, "inputs", "gas_job")
@@ -86,8 +91,9 @@ demo = gr.Interface(
86
  outputs=gr.Textbox(label="Response JSON"),
87
  title="OMRChecker API",
88
  description="傳送 Base64 圖片與模板 JSON,回傳辨識結果",
89
- api_name="predict" # 可選,指定端點名稱
90
  )
91
 
92
  if __name__ == "__main__":
 
93
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
24
 
25
  def process_omr_api(image_base64, template_json_str):
26
  logger.info("收到 OMR 請求")
27
+ # 參數校驗
28
+ if not image_base64 or len(image_base64) < 100:
29
+ return json.dumps({"status": "error", "message": "圖片 Base64 數據無效"})
30
+ if not template_json_str or len(template_json_str) < 10:
31
+ return json.dumps({"status": "error", "message": "模板 JSON 為空"})
32
  try:
33
  # 建立工作目錄
34
  job_dir = os.path.join(OMR_DIR, "inputs", "gas_job")
 
91
  outputs=gr.Textbox(label="Response JSON"),
92
  title="OMRChecker API",
93
  description="傳送 Base64 圖片與模板 JSON,回傳辨識結果",
94
+ api_name="predict"
95
  )
96
 
97
  if __name__ == "__main__":
98
+ # 不啟用 queue 以允許直接 POST 請求
99
  demo.launch(server_name="0.0.0.0", server_port=7860)