Update app.py
Browse files
app.py
CHANGED
|
@@ -10,9 +10,11 @@ from fastapi import FastAPI, File, UploadFile
|
|
| 10 |
# 🔐 基本設定
|
| 11 |
# ========================
|
| 12 |
PASSWORD = os.getenv("APP_PASSWORD", "defaultpass")
|
| 13 |
-
MAX_SIZE = 25 * 1024 * 1024
|
| 14 |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# ========================
|
| 18 |
# 🎧 音訊轉錄核心
|
|
@@ -58,7 +60,7 @@ def transcribe_core(path: str, model: str = "whisper-1"):
|
|
| 58 |
return full, summ
|
| 59 |
|
| 60 |
# ========================
|
| 61 |
-
# 🌐
|
| 62 |
# ========================
|
| 63 |
@app.post("/api/transcribe")
|
| 64 |
async def api_transcribe(file: UploadFile = File(...)):
|
|
@@ -72,10 +74,11 @@ async def api_transcribe(file: UploadFile = File(...)):
|
|
| 72 |
|
| 73 |
@app.get("/health")
|
| 74 |
def health():
|
|
|
|
| 75 |
return {"status": "ok", "time": int(time.time())}
|
| 76 |
|
| 77 |
# ========================
|
| 78 |
-
# 💬 Gradio
|
| 79 |
# ========================
|
| 80 |
def transcribe_with_pw(password, file):
|
| 81 |
if password.strip() != PASSWORD:
|
|
@@ -97,7 +100,12 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 97 |
run.click(transcribe_with_pw, [pw, f], [s, t, su])
|
| 98 |
|
| 99 |
# ========================
|
| 100 |
-
# 🚀 啟動(單一
|
| 101 |
# ========================
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# 🔐 基本設定
|
| 11 |
# ========================
|
| 12 |
PASSWORD = os.getenv("APP_PASSWORD", "defaultpass")
|
| 13 |
+
MAX_SIZE = 25 * 1024 * 1024
|
| 14 |
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 15 |
+
|
| 16 |
+
# FastAPI App for捷徑 API
|
| 17 |
+
app = FastAPI()
|
| 18 |
|
| 19 |
# ========================
|
| 20 |
# 🎧 音訊轉錄核心
|
|
|
|
| 60 |
return full, summ
|
| 61 |
|
| 62 |
# ========================
|
| 63 |
+
# 🌐 FastAPI 端點(捷徑用)
|
| 64 |
# ========================
|
| 65 |
@app.post("/api/transcribe")
|
| 66 |
async def api_transcribe(file: UploadFile = File(...)):
|
|
|
|
| 74 |
|
| 75 |
@app.get("/health")
|
| 76 |
def health():
|
| 77 |
+
"""捷徑可先 ping 這個確認服務運作中"""
|
| 78 |
return {"status": "ok", "time": int(time.time())}
|
| 79 |
|
| 80 |
# ========================
|
| 81 |
+
# 💬 Gradio 介面
|
| 82 |
# ========================
|
| 83 |
def transcribe_with_pw(password, file):
|
| 84 |
if password.strip() != PASSWORD:
|
|
|
|
| 100 |
run.click(transcribe_with_pw, [pw, f], [s, t, su])
|
| 101 |
|
| 102 |
# ========================
|
| 103 |
+
# 🚀 啟動(單一埠)
|
| 104 |
# ========================
|
| 105 |
+
# 讓 Gradio 介面掛載到 FastAPI
|
| 106 |
+
gr.mount_gradio_app(app, demo, path="/")
|
| 107 |
+
|
| 108 |
+
# Hugging Face 自動綁定 port=7860,不用手動設定
|
| 109 |
+
if __name__ == "__main__":
|
| 110 |
+
import uvicorn
|
| 111 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|