Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# app.py (Hugging Face Space用)
|
| 2 |
import uvicorn
|
| 3 |
from fastapi import FastAPI, Depends, HTTPException, status
|
| 4 |
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
|
@@ -13,7 +12,6 @@ def authenticate(credentials: HTTPBasicCredentials = Depends(security)):
|
|
| 13 |
correct_username = "admin"
|
| 14 |
correct_password = "password123"
|
| 15 |
|
| 16 |
-
# ユーザー名とパスワードが一致するか確認
|
| 17 |
if credentials.username != correct_username or credentials.password != correct_password:
|
| 18 |
raise HTTPException(
|
| 19 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
@@ -25,13 +23,12 @@ def authenticate(credentials: HTTPBasicCredentials = Depends(security)):
|
|
| 25 |
# ルート (/) - index.html を表示
|
| 26 |
@app.get("/")
|
| 27 |
async def read_index(username: str = Depends(authenticate)):
|
| 28 |
-
# ファイルが存在するか確認(念のため)
|
| 29 |
if os.path.exists('index.html'):
|
| 30 |
return FileResponse('index.html')
|
| 31 |
else:
|
| 32 |
return "index.htmlが見つかりません。ファイルをアップロードしてください。"
|
| 33 |
|
| 34 |
-
# 業務ポータル (/bussiness_portal)
|
| 35 |
@app.get("/bussiness_portal")
|
| 36 |
async def read_bussiness_portal(username: str = Depends(authenticate)):
|
| 37 |
file_path = 'bussiness_portal.html'
|
|
@@ -40,20 +37,25 @@ async def read_bussiness_portal(username: str = Depends(authenticate)):
|
|
| 40 |
else:
|
| 41 |
return f"{file_path}が見つかりません。"
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
async def read_entry_info(username: str = Depends(authenticate)):
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
| 47 |
if os.path.exists(file_path):
|
| 48 |
return FileResponse(file_path)
|
| 49 |
else:
|
|
|
|
|
|
|
| 50 |
return f"{file_path}が見つかりません。"
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
# 【修正箇所】
|
| 54 |
-
# 1. URLを "/guide" から "/guide.html" に変更(HTML側のリンクと合わせるため)
|
| 55 |
-
# 2. 関数名を "read_entry_info" から "read_guide" に変更(重複エラー回避)
|
| 56 |
-
# ------------------------------------------------------------------
|
| 57 |
@app.get("/guide.html")
|
| 58 |
async def read_guide(username: str = Depends(authenticate)):
|
| 59 |
file_path = 'guide.html'
|
|
|
|
|
|
|
| 1 |
import uvicorn
|
| 2 |
from fastapi import FastAPI, Depends, HTTPException, status
|
| 3 |
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
|
|
|
| 12 |
correct_username = "admin"
|
| 13 |
correct_password = "password123"
|
| 14 |
|
|
|
|
| 15 |
if credentials.username != correct_username or credentials.password != correct_password:
|
| 16 |
raise HTTPException(
|
| 17 |
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
|
|
| 23 |
# ルート (/) - index.html を表示
|
| 24 |
@app.get("/")
|
| 25 |
async def read_index(username: str = Depends(authenticate)):
|
|
|
|
| 26 |
if os.path.exists('index.html'):
|
| 27 |
return FileResponse('index.html')
|
| 28 |
else:
|
| 29 |
return "index.htmlが見つかりません。ファイルをアップロードしてください。"
|
| 30 |
|
| 31 |
+
# 業務ポータル (/bussiness_portal)
|
| 32 |
@app.get("/bussiness_portal")
|
| 33 |
async def read_bussiness_portal(username: str = Depends(authenticate)):
|
| 34 |
file_path = 'bussiness_portal.html'
|
|
|
|
| 37 |
else:
|
| 38 |
return f"{file_path}が見つかりません。"
|
| 39 |
|
| 40 |
+
# ------------------------------------------------------------------
|
| 41 |
+
# 【修正箇所】リンク切れ対策
|
| 42 |
+
# guide.htmlの戻るボタン (<a href="entry_info.html">) に合わせて
|
| 43 |
+
# URLパスを "/entry_info.html" に変更しました。
|
| 44 |
+
# ------------------------------------------------------------------
|
| 45 |
+
@app.get("/entry_info04.html")
|
| 46 |
async def read_entry_info(username: str = Depends(authenticate)):
|
| 47 |
+
# ここで指定するファイル名は、実際にアップロードしたファイル名に合わせてください
|
| 48 |
+
# 直近で作成したコードは entry_info.html として保存されている想定です
|
| 49 |
+
file_path = 'entry_info.html'
|
| 50 |
+
|
| 51 |
if os.path.exists(file_path):
|
| 52 |
return FileResponse(file_path)
|
| 53 |
else:
|
| 54 |
+
# もしファイル名が entry_info04.html のままであれば、
|
| 55 |
+
# 上記の file_path = 'entry_info04.html' に書き換えてください
|
| 56 |
return f"{file_path}が見つかりません。"
|
| 57 |
|
| 58 |
+
# ガイドページ (/guide.html)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
@app.get("/guide.html")
|
| 60 |
async def read_guide(username: str = Depends(authenticate)):
|
| 61 |
file_path = 'guide.html'
|