feat: whisper使用开源模型
Browse files- main.py +14 -3
- requirements.txt +1 -38
main.py
CHANGED
@@ -7,6 +7,8 @@ from langchain import OpenAI
|
|
7 |
from langchain.chains import ConversationChain
|
8 |
from langchain.memory import ConversationSummaryBufferMemory
|
9 |
from langchain.chat_models import ChatOpenAI
|
|
|
|
|
10 |
|
11 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
12 |
did_api_key = os.environ.get('DID_API_KEY')
|
@@ -100,13 +102,22 @@ def predict(input, history=[]):
|
|
100 |
return responses, video_html, history
|
101 |
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
# 通过openai whisper 语音识别
|
104 |
def transcribe(audio):
|
105 |
os.rename(audio, audio + '.wav')
|
106 |
audio_file = open(audio + '.wav', "rb")
|
107 |
-
|
108 |
-
|
109 |
-
return
|
110 |
|
111 |
|
112 |
def process_audio(audio, history=[]):
|
|
|
7 |
from langchain.chains import ConversationChain
|
8 |
from langchain.memory import ConversationSummaryBufferMemory
|
9 |
from langchain.chat_models import ChatOpenAI
|
10 |
+
from transformers import pipeline
|
11 |
+
|
12 |
|
13 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
14 |
did_api_key = os.environ.get('DID_API_KEY')
|
|
|
102 |
return responses, video_html, history
|
103 |
|
104 |
|
105 |
+
# 通过openai whisper 语音识别
|
106 |
+
# def transcribe(audio):
|
107 |
+
# os.rename(audio, audio + '.wav')
|
108 |
+
# audio_file = open(audio + '.wav', "rb")
|
109 |
+
# transcript = openai.Audio.transcribe(
|
110 |
+
# "whisper-1", audio_file, prompt="这是一段简体中文的问题。")
|
111 |
+
# return transcript['text']
|
112 |
+
|
113 |
+
|
114 |
# 通过openai whisper 语音识别
|
115 |
def transcribe(audio):
|
116 |
os.rename(audio, audio + '.wav')
|
117 |
audio_file = open(audio + '.wav', "rb")
|
118 |
+
transcriber = pipeline(model="openai/whisper-medium", device=0)
|
119 |
+
result = transcriber(audio_file)
|
120 |
+
return result['text']
|
121 |
|
122 |
|
123 |
def process_audio(audio, history=[]):
|
requirements.txt
CHANGED
@@ -1,45 +1,8 @@
|
|
1 |
-
# attr==0.3.2
|
2 |
-
# blobfile==2.0.2
|
3 |
-
# brotli==1.0.9
|
4 |
-
# brotlicffi==1.0.9.2
|
5 |
-
# ConfigParser==6.0.0
|
6 |
-
# contextlib2==21.6.0
|
7 |
-
# cryptography==41.0.3
|
8 |
-
# Cython==3.0.0
|
9 |
-
# dl==0.1.0
|
10 |
-
# docutils==0.20.1
|
11 |
-
# gradio==3.39.0
|
12 |
-
# HTMLParser==0.0.2
|
13 |
-
# importlib_metadata==6.8.0
|
14 |
-
# ipython==8.14.0
|
15 |
-
# ipywidgets==8.1.0
|
16 |
-
# Jinja2==3.1.2
|
17 |
-
# jnius==1.1.0
|
18 |
-
# keyring==24.2.0
|
19 |
-
# langchain==0.0.249
|
20 |
-
# lockfile==0.12.2
|
21 |
-
# mock==5.1.0
|
22 |
-
# numpy==1.25.2
|
23 |
-
# openai==0.27.8
|
24 |
-
# ordereddict==1.1
|
25 |
-
# Pillow==10.0.0
|
26 |
-
# protobuf==4.23.4
|
27 |
-
# pyOpenSSL==23.2.0
|
28 |
-
# railroad==0.5.0
|
29 |
-
# simplejson==3.19.1
|
30 |
-
# Sphinx==7.1.2
|
31 |
-
# tornado==6.3.2
|
32 |
-
# truststore==0.7.0
|
33 |
-
# urllib3_secure_extra==0.1.0
|
34 |
-
# # wincertstore==0.2.1
|
35 |
-
# # xmlrpclib==1.0.1
|
36 |
-
# zstandard==0.21.0
|
37 |
-
# tiktoken==0.4.0
|
38 |
-
|
39 |
openai
|
40 |
langchain
|
41 |
requests
|
42 |
gradio
|
43 |
tiktoken
|
|
|
44 |
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
openai
|
2 |
langchain
|
3 |
requests
|
4 |
gradio
|
5 |
tiktoken
|
6 |
+
transformers
|
7 |
|
8 |
|