Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import torch
|
| 2 |
-
from transformers import
|
| 3 |
-
from transformers import
|
| 4 |
from datasets import load_dataset
|
| 5 |
import spacy
|
| 6 |
import gradio as gr
|
|
@@ -26,6 +26,8 @@ whisper_pipe = pipeline(
|
|
| 26 |
)
|
| 27 |
|
| 28 |
# DeepSeek-V3 ๆจกๅๅๅงๅ๏ผๆๆฌ็ๆ๏ผ
|
|
|
|
|
|
|
| 29 |
try:
|
| 30 |
deepseek_pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-V3", trust_remote_code=True)
|
| 31 |
except Exception as e:
|
|
@@ -34,13 +36,12 @@ except Exception as e:
|
|
| 34 |
# spaCy ๅๅงๅ๏ผๆๆฌๅ้ก่ๆจ็ฑค๏ผ
|
| 35 |
nlp = spacy.load("en_core_web_sm")
|
| 36 |
|
| 37 |
-
# ๅฎ็พฉ่็ๅฝๆธ
|
| 38 |
def process_audio(audio_file):
|
| 39 |
# ่ช้ณ่ฝๆๅญ
|
| 40 |
result = whisper_pipe(audio_file)["text"]
|
| 41 |
|
| 42 |
# ไฝฟ็จ DeepSeek ็ๆๅๆ๏ผๅฆๆๆๅๅ ่ผๆจกๅ๏ผ
|
| 43 |
-
|
| 44 |
messages = [{"role": "user", "content": result}]
|
| 45 |
deepseek_response = deepseek_pipe(messages)[0]["generated_text"]
|
| 46 |
|
|
@@ -48,24 +49,10 @@ def process_audio(audio_file):
|
|
| 48 |
doc = nlp(deepseek_response)
|
| 49 |
entities = [(ent.text, ent.label_) for ent in doc.ents]
|
| 50 |
|
| 51 |
-
return result, deepseek_response, entities
|
| 52 |
-
|
| 53 |
-
except Exception as e:
|
| 54 |
-
return result, f"้ฏ่ชค๏ผ็กๆณ็ๆๅๆ - {e}", []
|
| 55 |
-
|
| 56 |
-
# Gradio ็้ข่จญ่จ
|
| 57 |
-
def interface(audio_file):
|
| 58 |
-
transcription_result_list # ๅฐ็ตๆๅ
่ฃ็บๅญๅ
ธไปฅ้ฉๆ Gradio ่ผธๅบๆ ผๅผ
|
| 59 |
-
|
| 60 |
-
try:
|
| 61 |
-
transcription_result_list # ้่ฃก้่ฆไฟฎๆนไปฅ้ฉๆๆฐ็่ฟๅๆ ผๅผ
|
| 62 |
-
|
| 63 |
-
transcription_result_dict # ้่ฃก้่ฆไฟฎๆนไปฅ้ฉๆๆฐ็่ฟๅๆ ผๅผ
|
| 64 |
-
|
| 65 |
return {
|
| 66 |
-
"Transcription (Whisper)":
|
| 67 |
-
"AI Response (DeepSeek)":
|
| 68 |
-
"Extracted Entities (spaCy)":
|
| 69 |
|
| 70 |
}
|
| 71 |
|
|
@@ -90,9 +77,4 @@ with gr.Blocks() as app:
|
|
| 90 |
audio_input=gr.Audio(source="microphone", type="filepath", label="ไธๅณ่ช้ณ")
|
| 91 |
output_text=gr.JSON(label="็ตๆ")
|
| 92 |
|
| 93 |
-
submit_button=gr.Button("
|
| 94 |
-
submit_button.click(fn=lambda x: process_audio(x), inputs=[audio_input], outputs=[output_text])
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
if __name__ == "__main__":
|
| 98 |
-
app.launch()
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
| 3 |
+
from transformers import pipeline
|
| 4 |
from datasets import load_dataset
|
| 5 |
import spacy
|
| 6 |
import gradio as gr
|
|
|
|
| 26 |
)
|
| 27 |
|
| 28 |
# DeepSeek-V3 ๆจกๅๅๅงๅ๏ผๆๆฌ็ๆ๏ผ
|
| 29 |
+
deepseek_pipe = None # ้ ่จญๅผ๏ผไปฅ้ฒๆจกๅๅ ่ผๅคฑๆ
|
| 30 |
+
|
| 31 |
try:
|
| 32 |
deepseek_pipe = pipeline("text-generation", model="deepseek-ai/DeepSeek-V3", trust_remote_code=True)
|
| 33 |
except Exception as e:
|
|
|
|
| 36 |
# spaCy ๅๅงๅ๏ผๆๆฌๅ้ก่ๆจ็ฑค๏ผ
|
| 37 |
nlp = spacy.load("en_core_web_sm")
|
| 38 |
|
|
|
|
| 39 |
def process_audio(audio_file):
|
| 40 |
# ่ช้ณ่ฝๆๅญ
|
| 41 |
result = whisper_pipe(audio_file)["text"]
|
| 42 |
|
| 43 |
# ไฝฟ็จ DeepSeek ็ๆๅๆ๏ผๅฆๆๆๅๅ ่ผๆจกๅ๏ผ
|
| 44 |
+
if deepseek_pipe is not None:
|
| 45 |
messages = [{"role": "user", "content": result}]
|
| 46 |
deepseek_response = deepseek_pipe(messages)[0]["generated_text"]
|
| 47 |
|
|
|
|
| 49 |
doc = nlp(deepseek_response)
|
| 50 |
entities = [(ent.text, ent.label_) for ent in doc.ents]
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
return {
|
| 53 |
+
"Transcription (Whisper)": result,
|
| 54 |
+
"AI Response (DeepSeek)": deepseek_response,
|
| 55 |
+
"Extracted Entities (spaCy)": entities,
|
| 56 |
|
| 57 |
}
|
| 58 |
|
|
|
|
| 77 |
audio_input=gr.Audio(source="microphone", type="filepath", label="ไธๅณ่ช้ณ")
|
| 78 |
output_text=gr.JSON(label="็ตๆ")
|
| 79 |
|
| 80 |
+
submit_button=gr.Button("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|