hsuwill000 commited on
Commit
e5d3a7a
·
verified ·
1 Parent(s): 0745678

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -37,7 +37,6 @@ def respond(prompt, history):
37
  def maxtest(prompt):
38
  return prompt
39
 
40
- # 定義主 Blocks,只包含聊天介面
41
  with gr.Blocks() as demo:
42
  gr.Markdown("# DeepSeek-R1-Distill-Qwen-1.5B-openvino")
43
  with gr.Tabs():
@@ -47,21 +46,19 @@ with gr.Blocks() as demo:
47
  title="聊天介面",
48
  description="DeepSeek-R1-Distill-Qwen-1.5B-openvino 聊天接口"
49
  )
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- # 定義隱藏的 API 介面(不會 render 到 UI)
52
- hidden_api = gr.Interface(
53
- fn=maxtest,
54
- inputs=gr.Textbox(label="Prompt"),
55
- outputs="text",
56
- api_name="/maxtest",
57
- title="MaxTest API",
58
- description="回傳輸入內容的測試 API",
59
- visible=False
60
- )
61
-
62
- # 啟動時,將 hidden_api 作為一個 FastAPI 子應用掛載到主應用上
63
  if __name__ == "__main__":
64
- # 使用 demo.launch() 返回 FastAPI 應用實例(注意:此方法行為可能因 Gradio 版本而異)
65
- app, local_url, share_url = demo.launch(server_name="0.0.0.0", server_port=7860, share=True, inline=False)
66
- # 掛載 hidden_api 的 FastAPI app 到 /maxtest
67
- app.mount("/maxtest", hidden_api.app)
 
37
  def maxtest(prompt):
38
  return prompt
39
 
 
40
  with gr.Blocks() as demo:
41
  gr.Markdown("# DeepSeek-R1-Distill-Qwen-1.5B-openvino")
42
  with gr.Tabs():
 
46
  title="聊天介面",
47
  description="DeepSeek-R1-Distill-Qwen-1.5B-openvino 聊天接口"
48
  )
49
+ # 將隱藏的接口作為一個組件加入 Blocks,設定 visible=False
50
+ hidden_api = gr.Interface(
51
+ fn=respond,
52
+ inputs=gr.Textbox(label="Prompt"),
53
+ outputs="text",
54
+ api_name="/hchat",
55
+ title="MaxTest API",
56
+ description="回傳輸入內容的測試 API",
57
+ visible=False
58
+ )
59
+ # 使用 .render() 將 hidden_api 組件加入佈局,雖然 UI 不會顯示,但 API 端點仍會註冊
60
+ #hidden_api.render()
61
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  if __name__ == "__main__":
63
+ print("Launching Gradio app...")
64
+ demo.launch(server_name="0.0.0.0", server_port=7860, share=True)