SissiFeng commited on
Commit
6d86244
·
1 Parent(s): d3419a2
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -439,22 +439,26 @@ with demo:
439
  logger.info(f"API call: send_print_parameters with nozzle={nozzle_temp}, bed={bed_temp}, speed={print_speed}, fan={fan_speed}")
440
  return send_print_parameters(nozzle_temp, bed_temp, print_speed, fan_speed)
441
 
442
- # 注册 API 端点 - 这里是关键修改,将这些调用移到 with demo: 上下文内
 
 
 
 
443
  capture_frame_api = demo.load(
444
  fn=api_capture_frame,
445
  inputs=[
446
- gr.Textbox(label="Image URL"), # 接收图像 URL
447
  gr.Checkbox(label="Use Test Image", value=False),
448
  gr.Textbox(label="Test Image Name", value="")
449
  ],
450
- outputs="json",
451
  api_name="capture_frame"
452
  )
453
 
454
  lambda_api = demo.load(
455
  fn=api_lambda,
456
  inputs=[
457
- gr.Textbox(label="Image Base64 or URL"), # 接收图像数据或 URL
458
  gr.Number(label="Nozzle Temperature", value=200),
459
  gr.Number(label="Bed Temperature", value=60),
460
  gr.Number(label="Print Speed", value=60),
@@ -462,14 +466,14 @@ with demo:
462
  gr.Checkbox(label="Use Test Image", value=False),
463
  gr.Textbox(label="Test Image Name", value="")
464
  ],
465
- outputs="json",
466
  api_name="lambda"
467
  )
468
 
469
  get_data_api = demo.load(
470
  fn=api_get_data,
471
  inputs=None,
472
- outputs="json",
473
  api_name="get_data"
474
  )
475
 
@@ -481,7 +485,7 @@ with demo:
481
  gr.Number(label="Print Speed", value=60),
482
  gr.Number(label="Fan Speed", value=100)
483
  ],
484
- outputs="text",
485
  api_name="send_print_parameters"
486
  )
487
 
 
439
  logger.info(f"API call: send_print_parameters with nozzle={nozzle_temp}, bed={bed_temp}, speed={print_speed}, fan={fan_speed}")
440
  return send_print_parameters(nozzle_temp, bed_temp, print_speed, fan_speed)
441
 
442
+ # 创建用于 API 输出的 JSON 组件
443
+ api_json_output = gr.JSON()
444
+ api_text_output = gr.Textbox()
445
+
446
+ # 注册 API 端点,使用 Gradio 组件作为输出
447
  capture_frame_api = demo.load(
448
  fn=api_capture_frame,
449
  inputs=[
450
+ gr.Textbox(label="Image URL"),
451
  gr.Checkbox(label="Use Test Image", value=False),
452
  gr.Textbox(label="Test Image Name", value="")
453
  ],
454
+ outputs=api_json_output, # 使用 JSON 组件而不是字符串 "json"
455
  api_name="capture_frame"
456
  )
457
 
458
  lambda_api = demo.load(
459
  fn=api_lambda,
460
  inputs=[
461
+ gr.Textbox(label="Image Base64 or URL"),
462
  gr.Number(label="Nozzle Temperature", value=200),
463
  gr.Number(label="Bed Temperature", value=60),
464
  gr.Number(label="Print Speed", value=60),
 
466
  gr.Checkbox(label="Use Test Image", value=False),
467
  gr.Textbox(label="Test Image Name", value="")
468
  ],
469
+ outputs=api_json_output, # 使用 JSON 组件而不是字符串 "json"
470
  api_name="lambda"
471
  )
472
 
473
  get_data_api = demo.load(
474
  fn=api_get_data,
475
  inputs=None,
476
+ outputs=api_json_output, # 使用 JSON 组件而不是字符串 "json"
477
  api_name="get_data"
478
  )
479
 
 
485
  gr.Number(label="Print Speed", value=60),
486
  gr.Number(label="Fan Speed", value=100)
487
  ],
488
+ outputs=api_text_output, # 使用 Textbox 组件而不是字符串 "text"
489
  api_name="send_print_parameters"
490
  )
491