hchcsuim commited on
Commit
0ee3307
·
1 Parent(s): 31c163f

Fix Hugging Face Spaces deployment: set server_name to 0.0.0.0 and enable share in Spaces environment

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -955,13 +955,18 @@ if __name__ == "__main__":
955
  print("No GPU detected")
956
 
957
  # REMEMBER: Update requirements.txt with accelerate, scipy, torchvision, peft
 
 
 
 
 
958
  demo.launch(
959
  debug=True,
960
  max_threads=4, # 減少最大線程數,提高穩定性
961
  show_error=True, # 顯示錯誤詳情
962
- # 移除 server_name 參數,讓應用程式監聽所有網絡接口
963
- # 或者使用 server_name="0.0.0.0" 明確指定監聽所有接口
964
  server_port=7860, # 指定端口
965
  quiet=False, # 顯示所有日誌
966
- prevent_thread_lock=True # 防止線程鎖定
 
967
  )
 
955
  print("No GPU detected")
956
 
957
  # REMEMBER: Update requirements.txt with accelerate, scipy, torchvision, peft
958
+
959
+ # 檢查是否在 Hugging Face Spaces 環境中
960
+ import os
961
+ is_spaces = os.environ.get("SPACE_ID") is not None
962
+
963
  demo.launch(
964
  debug=True,
965
  max_threads=4, # 減少最大線程數,提高穩定性
966
  show_error=True, # 顯示錯誤詳情
967
+ server_name="0.0.0.0", # 明確指定監聽所有接口
 
968
  server_port=7860, # 指定端口
969
  quiet=False, # 顯示所有日誌
970
+ prevent_thread_lock=True, # 防止線程鎖定
971
+ share=is_spaces # 在 Spaces 環境中啟用分享
972
  )