Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,15 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from dotenv import load_dotenv
|
| 3 |
import os
|
| 4 |
from elevenlabs_stt import transcribe_audio as transcribe_audio_elevenlabs
|
| 5 |
-
from whisper_stt import transcribe_audio_whisper
|
| 6 |
from transcript_refiner import refine_transcript
|
| 7 |
from utils import check_file_size, split_large_audio
|
| 8 |
import logging
|
| 9 |
|
| 10 |
-
# 載入環境變數
|
| 11 |
-
load_dotenv()
|
| 12 |
-
|
| 13 |
# 設定日誌
|
| 14 |
logging.basicConfig(level=logging.INFO)
|
| 15 |
logger = logging.getLogger(__name__)
|
|
@@ -66,11 +62,11 @@ def process_audio(
|
|
| 66 |
"""處理音訊檔案並返回結果"""
|
| 67 |
try:
|
| 68 |
# 檢查必要的 API 金鑰
|
| 69 |
-
if not openai_api_key:
|
| 70 |
-
return "
|
| 71 |
|
| 72 |
-
if transcription_service == "ElevenLabs" and not elevenlabs_api_key:
|
| 73 |
-
return "
|
| 74 |
|
| 75 |
# 初始化變數
|
| 76 |
full_transcript = ""
|
|
@@ -156,6 +152,10 @@ def process_audio(
|
|
| 156 |
except Exception as e:
|
| 157 |
logger.error(f"處理失敗:{str(e)}")
|
| 158 |
return f"處理失敗:{str(e)}", "", "", 0, "NT$ 0.00"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
def create_gradio_interface():
|
| 161 |
"""建立 Gradio 介面"""
|
|
@@ -172,14 +172,25 @@ def create_gradio_interface():
|
|
| 172 |
|
| 173 |
# API 金鑰
|
| 174 |
with gr.Group():
|
| 175 |
-
gr.Markdown("### API 金鑰設定
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
openai_key = gr.Textbox(
|
| 177 |
label="OpenAI API 金鑰",
|
| 178 |
-
type="password"
|
|
|
|
|
|
|
|
|
|
| 179 |
)
|
| 180 |
elevenlabs_key = gr.Textbox(
|
| 181 |
label="ElevenLabs API 金鑰",
|
| 182 |
-
type="password"
|
|
|
|
|
|
|
|
|
|
| 183 |
)
|
| 184 |
|
| 185 |
# 模型選擇
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import os
|
| 3 |
from elevenlabs_stt import transcribe_audio as transcribe_audio_elevenlabs
|
| 4 |
+
from whisper_stt import transcribe_audio_whisper
|
| 5 |
from transcript_refiner import refine_transcript
|
| 6 |
from utils import check_file_size, split_large_audio
|
| 7 |
import logging
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
# 設定日誌
|
| 10 |
logging.basicConfig(level=logging.INFO)
|
| 11 |
logger = logging.getLogger(__name__)
|
|
|
|
| 62 |
"""處理音訊檔案並返回結果"""
|
| 63 |
try:
|
| 64 |
# 檢查必要的 API 金鑰
|
| 65 |
+
if not openai_api_key or len(openai_api_key.strip()) < 20:
|
| 66 |
+
return "請提供有效的 OpenAI API 金鑰", "", "", 0, "NT$ 0.00"
|
| 67 |
|
| 68 |
+
if transcription_service == "ElevenLabs" and (not elevenlabs_api_key or len(elevenlabs_api_key.strip()) < 20):
|
| 69 |
+
return "請提供有效的 ElevenLabs API 金鑰", "", "", 0, "NT$ 0.00"
|
| 70 |
|
| 71 |
# 初始化變數
|
| 72 |
full_transcript = ""
|
|
|
|
| 152 |
except Exception as e:
|
| 153 |
logger.error(f"處理失敗:{str(e)}")
|
| 154 |
return f"處理失敗:{str(e)}", "", "", 0, "NT$ 0.00"
|
| 155 |
+
finally:
|
| 156 |
+
# 清除敏感資訊
|
| 157 |
+
del openai_api_key
|
| 158 |
+
del elevenlabs_api_key
|
| 159 |
|
| 160 |
def create_gradio_interface():
|
| 161 |
"""建立 Gradio 介面"""
|
|
|
|
| 172 |
|
| 173 |
# API 金鑰
|
| 174 |
with gr.Group():
|
| 175 |
+
gr.Markdown("""### API 金鑰設定
|
| 176 |
+
> **安全提示:**
|
| 177 |
+
> - API 金鑰僅在當前處理中使用,不會被儲存
|
| 178 |
+
> - 每次使用需重新輸入以確保安全性
|
| 179 |
+
> - 請勿與他人分享您的 API 金鑰
|
| 180 |
+
""")
|
| 181 |
openai_key = gr.Textbox(
|
| 182 |
label="OpenAI API 金鑰",
|
| 183 |
+
type="password",
|
| 184 |
+
placeholder="sk-...",
|
| 185 |
+
value="",
|
| 186 |
+
every=None # 確保不會被快取
|
| 187 |
)
|
| 188 |
elevenlabs_key = gr.Textbox(
|
| 189 |
label="ElevenLabs API 金鑰",
|
| 190 |
+
type="password",
|
| 191 |
+
placeholder="輸入您的 ElevenLabs API 金鑰",
|
| 192 |
+
value="",
|
| 193 |
+
every=None # 確保不會被快取
|
| 194 |
)
|
| 195 |
|
| 196 |
# 模型選擇
|