File size: 4,383 Bytes
1e13199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env python3
"""
現在のプロジェクトをHugging Face Docker Spaceに準備するスクリプト
"""

import os
import shutil
import subprocess

def create_dockerfile_for_current_project():
    """
    現在のプロジェクト用のDockerfileを作成
    """
    
    dockerfile_content = """FROM python:3.9-slim

WORKDIR /app

# システムの依存関係をインストール
RUN apt-get update && apt-get install -y \\
    gcc \\
    && rm -rf /var/lib/apt/lists/*

# 要件をコピーしてインストール
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# アプリケーションファイルをコピー
COPY . .

# ポートを公開 (Hugging Face Spacesは7860を使用)
EXPOSE 7860

# 環境変数を設定
ENV PORT=7860

# アプリケーションを起動
CMD ["python", "app.py"]
"""
    
    with open("Dockerfile", "w", encoding="utf-8") as f:
        f.write(dockerfile_content)
    
    print("✅ Dockerfile created")

def create_requirements_txt():
    """
    requirements.txtを作成または更新
    """
    
    requirements = [
        "fastapi==0.104.1",
        "uvicorn==0.24.0",
        "django==4.2.7",
        "pydantic==2.5.0",
        "requests==2.31.0",
        "python-multipart==0.0.6",
        "sqlalchemy==2.0.23",
        "python-jose[cryptography]==3.3.0",
        "passlib[bcrypt]==1.7.4",
        "python-dotenv==1.0.0",
        "jinja2==3.1.2",
        "aiofiles==23.2.1"
    ]
    
    with open("requirements.txt", "w", encoding="utf-8") as f:
        for req in requirements:
            f.write(f"{req}\\n")
    
    print("✅ requirements.txt created")

def create_hf_readme():
    """
    Hugging Face Spaces用のREADME.mdを作成
    """
    
    readme_content = """---
title: FastAPI Django Main Live
emoji: 🚀
colorFrom: blue
colorTo: red
sdk: docker
pinned: false
license: mit
---

# FastAPI Django Main Live

高性能なFastAPI + Django統合アプリケーション

## 🚀 概要

このスペースは、FastAPIとDjangoを統合したライブアプリケーションです。

## ✨ 機能

- **FastAPI** - 高性能なPython Webフレームワーク
- **Django** - 成熟したWebアプリケーションフレームワーク
- **Docker** - コンテナ化されたデプロイメント
- **自動デプロイ** - Hugging Face Spacesでの自動デプロイ

## 🛠️ 使用技術

- Python 3.9+
- FastAPI
- Django
- Docker
- Uvicorn

## 📋 API エンドポイント

- `GET /` - ヘルスチェック
- `GET /health` - システムステータス
- `GET /docs` - API ドキュメント (Swagger UI)

## 🔧 ローカル開発

```bash
# 依存関係のインストール
pip install -r requirements.txt

# アプリケーションの起動
python app.py
```

## 🐳 Docker

```bash
# イメージのビルド
docker build -t fastapi-django-app .

# コンテナの実行
docker run -p 7860:7860 fastapi-django-app
```

## 📝 ライセンス

MIT License

## 👤 作成者

kenken999
"""
    
    with open("README.md", "w", encoding="utf-8") as f:
        f.write(readme_content)
    
    print("✅ README.md created")

def create_gitignore():
    """
    .gitignoreファイルを作成
    """
    
    gitignore_content = """# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Django
*.log
local_settings.py
db.sqlite3
media/

# Environment
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db

# Docker
.dockerignore
"""
    
    with open(".gitignore", "w", encoding="utf-8") as f:
        f.write(gitignore_content)
    
    print("✅ .gitignore created")

def main():
    """メイン関数"""
    
    print("🚀 Hugging Face Docker Space用のファイルを準備中...")
    
    # 各ファイルを作成
    create_dockerfile_for_current_project()
    create_requirements_txt()
    create_hf_readme()
    create_gitignore()
    
    print("""
🎉 プロジェクトの準備完了!

📋 次の手順:
1. app.py を確認・編集
2. git add .
3. git commit -m "Prepare for Hugging Face Docker Space"
4. git push

🌐 プッシュ後、Hugging Face Spacesで自動的にビルドされます。
    """)

if __name__ == "__main__":
    main()