Download app.py from soiz/cookie: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/soiz/cookie/resolve/main/app.py
- Command line
-
hf download hf://spaces/soiz/cookie/app.py
-
curl -L -o app.py https://huggingface.co/spaces/soiz/cookie/resolve/main/app.py
1.2 kB
| import os | |
| from flask import Flask, send_from_directory, abort | |
| # リポジトリのクローンを行う | |
| def clone_repo(): | |
| # クローンしたかどうかを判定するファイル | |
| clone_flag = "repo_cloned.flag" | |
| if not os.path.exists(clone_flag): | |
| print("Cloning the repository...") | |
| result = os.system("git clone https://github.com/ozh/cookieclicker.git .") | |
| if result != 0: | |
| print("Error: Failed to clone the repository.") | |
| else: | |
| # クローン完了後にフラグファイルを作成 | |
| with open(clone_flag, 'w') as f: | |
| f.write("Repository has been cloned.") | |
| else: | |
| print("Repository already cloned.") | |
| # クローンを実行 | |
| clone_repo() | |
| # Flaskアプリケーションの設定 | |
| app = Flask(__name__) | |
| # ルートでindex.htmlを表示 | |
| def index(): | |
| # index.htmlが存在しない場合は404エラー | |
| if not os.path.exists("index.html"): | |
| return abort(404, description="index.html not found.") | |
| return send_from_directory('.', 'index.html') | |
| if __name__ == '__main__': | |
| # port 7860でFlaskアプリを起動 | |
| app.run(host='0.0.0.0', port=7860) | |