Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,19 +22,6 @@ whisper_pipe = pipeline(
|
|
| 22 |
feature_extractor=whisper_processor.feature_extractor,
|
| 23 |
device=device)
|
| 24 |
|
| 25 |
-
# DeepSeek-V3 模型初始化(文本生成)
|
| 26 |
-
deepseek_pipe = None # 預設值,以防模型加載失敗
|
| 27 |
-
|
| 28 |
-
try:
|
| 29 |
-
|
| 30 |
-
# 這裡需要添加正確的內容以避免 IndentationError
|
| 31 |
-
|
| 32 |
-
deepseek_pipe=pipeline("text-generation",model="t5-base") # 暫時使用 T5 作為替代
|
| 33 |
-
|
| 34 |
-
except Exception as e:
|
| 35 |
-
|
| 36 |
-
print(f"加載模型時出現錯誤:{e}")
|
| 37 |
-
|
| 38 |
# spaCy 初始化(文本分類與標籤)
|
| 39 |
nlp=None
|
| 40 |
|
|
@@ -48,30 +35,37 @@ except Exception as e:
|
|
| 48 |
|
| 49 |
def process_audio(audio_file):
|
| 50 |
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
return {
|
| 67 |
-
"Transcription (Whisper)": result,
|
| 68 |
-
"AI Response (T5)": deepseek_response,# 修改為 T5 回應以避免與原來不同步
|
| 69 |
-
"Extracted Entities (spaCy)": entities}
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
|
| 76 |
|
| 77 |
|
|
|
|
| 22 |
feature_extractor=whisper_processor.feature_extractor,
|
| 23 |
device=device)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# spaCy 初始化(文本分類與標籤)
|
| 26 |
nlp=None
|
| 27 |
|
|
|
|
| 35 |
|
| 36 |
def process_audio(audio_file):
|
| 37 |
|
| 38 |
+
# 語音轉文字
|
| 39 |
|
| 40 |
+
result= whisper_pipe(audio_file)["text"]
|
| 41 |
|
| 42 |
+
# 使用 T5 作為替代模型
|
| 43 |
+
|
| 44 |
+
messages=[{"role": "user", "content": result}]
|
| 45 |
+
|
| 46 |
+
deepseek_response=""
|
| 47 |
+
|
| 48 |
+
try:
|
| 49 |
+
from transformers import pipeline
|
| 50 |
+
|
| 51 |
+
pipe=pipeline("text-generation",model="t5-base")
|
| 52 |
+
|
| 53 |
+
deepseek_response=pipe(messages)[0]["generated_text"]
|
| 54 |
|
| 55 |
+
# 使用 spaCy 分析文本
|
| 56 |
+
|
| 57 |
+
doc=nlp(deepseek_response) if nlp is not None else None
|
| 58 |
+
entities=[(ent.text, ent.label_) for ent in doc.ents] if doc is not None else []
|
| 59 |
+
|
| 60 |
+
return {
|
| 61 |
+
"Transcription (Whisper)": result,
|
| 62 |
+
"AI Response (T5)": deepseek_response,# 修改為 T5 回應以避免與原來不同步
|
| 63 |
+
"Extracted Entities (spaCy)": entities}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
+
except Exception as e:
|
| 66 |
+
return {
|
| 67 |
+
"Transcription (Whister)": result,# 保留原始轉錄內容
|
| 68 |
+
}
|
| 69 |
|
| 70 |
|
| 71 |
|