khjhs60199 commited on
Commit
03efb54
·
verified ·
1 Parent(s): 100c661

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -636,25 +636,23 @@ def create_interface():
636
  stats_refresh_btn.click(app.get_statistics, outputs=[stats_display])
637
  interface.load(app.get_statistics, outputs=[stats_display])
638
 
639
- return interface # ⬅️ 這裡是關鍵!一定要返回 interface
640
 
641
  # 啟動應用
642
  if __name__ == "__main__":
643
  import threading
644
 
645
- # 在背景啟動Flask API
646
- def run_flask():
647
- flask_app.run(host='0.0.0.0', port=7860, debug=False)
648
-
649
- flask_thread = threading.Thread(target=run_flask, daemon=True)
650
- flask_thread.start()
651
-
652
  print("🚀 啟動股市新聞情緒分析器...")
653
  print("📊 API接口: https://khjhs60199-pycrawing.hf.space/api")
654
  print("⚡ 自動功能: 系統啟動後自動檢測並爬取新聞")
655
 
656
- # 啟動Gradio介面
657
- interface = create_interface() # 修正:正確獲取interface
 
 
 
 
 
658
  interface.launch(
659
  server_name="0.0.0.0",
660
  server_port=7860,
 
636
  stats_refresh_btn.click(app.get_statistics, outputs=[stats_display])
637
  interface.load(app.get_statistics, outputs=[stats_display])
638
 
639
+ return interface
640
 
641
  # 啟動應用
642
  if __name__ == "__main__":
643
  import threading
644
 
 
 
 
 
 
 
 
645
  print("🚀 啟動股市新聞情緒分析器...")
646
  print("📊 API接口: https://khjhs60199-pycrawing.hf.space/api")
647
  print("⚡ 自動功能: 系統啟動後自動檢測並爬取新聞")
648
 
649
+ # 啟動Gradio介面,並使用Gradio內建的API端點
650
+ interface = create_interface()
651
+
652
+ # 掛載Flask API到Gradio的app
653
+ interface.mount_gradio_app(flask_app, path="/api")
654
+
655
+ # 只啟動Gradio介面,Flask API會自動整合
656
  interface.launch(
657
  server_name="0.0.0.0",
658
  server_port=7860,