Spaces:
Sleeping
Sleeping
update genmin
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import gradio as gr
|
|
5 |
import os
|
6 |
|
7 |
hugapikey=os.environ['openaikey']
|
|
|
8 |
MODEL_NAME = "seiching/whisper-small-seiching"
|
9 |
#MODEL_NAME = "openai/whisper-small"
|
10 |
BATCH_SIZE = 8
|
@@ -89,15 +90,17 @@ def process_chunks(openaikeystr,inputtext):
|
|
89 |
#openaikey.set_key(openaikeystr)
|
90 |
#print('process_chunk',openaikey.get_key())
|
91 |
chunks = split_into_chunks(text)
|
92 |
-
response=''
|
93 |
i=1
|
94 |
for chunk in chunks:
|
95 |
|
96 |
response=response+'第' +str(i)+'段\n'+call_openai_api(openaiobj,chunk)+'\n\n'
|
97 |
i=i+1
|
98 |
# response=response+call_openai_summary(openaiobj,chunk)
|
99 |
-
|
100 |
-
|
|
|
|
|
101 |
return finalresponse
|
102 |
# # Processes chunks in parallel
|
103 |
# with ThreadPoolExecutor() as executor:
|
@@ -208,15 +211,32 @@ file_transcribe = gr.Interface(
|
|
208 |
cache_examples=True,
|
209 |
allow_flagging="never",
|
210 |
)
|
211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
#text=transcribe_text
|
213 |
#openaikey.set_key(inputkey)
|
214 |
#openaikey = OpenAIKeyClass(inputkey)
|
215 |
print('ok')
|
216 |
-
if len(inputscript)>10:
|
217 |
-
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
# ainotestext=inputscript
|
221 |
#ainotestext=""
|
222 |
# with open('asr_resul.txt', 'w') as f:
|
@@ -228,7 +248,7 @@ def writenotes( apikeystr,inputscript):
|
|
228 |
return ainotestext
|
229 |
ainotes = gr.Interface(
|
230 |
fn=writenotes,
|
231 |
-
inputs=[gr.Textbox(label="OPEN AI API KEY",placeholder="請輸入sk..."),gr.Textbox(label="逐字稿",placeholder="若沒有做語音辨識,請輸入逐字稿")],
|
232 |
outputs="text",
|
233 |
layout="horizontal",
|
234 |
theme="huggingface",
|
|
|
5 |
import os
|
6 |
|
7 |
hugapikey=os.environ['openaikey']
|
8 |
+
genaikey=os.environ['genaikey']
|
9 |
MODEL_NAME = "seiching/whisper-small-seiching"
|
10 |
#MODEL_NAME = "openai/whisper-small"
|
11 |
BATCH_SIZE = 8
|
|
|
90 |
#openaikey.set_key(openaikeystr)
|
91 |
#print('process_chunk',openaikey.get_key())
|
92 |
chunks = split_into_chunks(text)
|
93 |
+
response='這是分段會議紀錄結果\n\n'
|
94 |
i=1
|
95 |
for chunk in chunks:
|
96 |
|
97 |
response=response+'第' +str(i)+'段\n'+call_openai_api(openaiobj,chunk)+'\n\n'
|
98 |
i=i+1
|
99 |
# response=response+call_openai_summary(openaiobj,chunk)
|
100 |
+
if i>2:
|
101 |
+
finalresponse=response+'\n\n 這是根據以上分段會議紀錄彙編如下 \n\n' +call_openai_api(openaiobj,response)
|
102 |
+
else:
|
103 |
+
finalresponse=response
|
104 |
return finalresponse
|
105 |
# # Processes chunks in parallel
|
106 |
# with ThreadPoolExecutor() as executor:
|
|
|
211 |
cache_examples=True,
|
212 |
allow_flagging="never",
|
213 |
)
|
214 |
+
import google.generativeai as genai
|
215 |
+
def gewritenote(inputscript):
|
216 |
+
api_key = gekey
|
217 |
+
genai.configure(api_key = api_key)
|
218 |
+
model = genai.GenerativeModel('gemini-pro')
|
219 |
+
genprompt='你是專業的會議紀錄製作員,請根據由語音辨識軟體將會議錄音所轉錄的逐字稿,也請注意逐字稿可能有錯,討論內容細節請略過,請列出經主席確認的會議決議,並要用比較正式及容易閱讀的寫法,避免口語化'
|
220 |
+
genprompt=genprompt+'#'+inputscript+'#'
|
221 |
+
response = model.generate_content( genprompt)
|
222 |
+
return response.text
|
223 |
+
def writenotes( LLMmodel,apikeystr,inputscript):
|
224 |
#text=transcribe_text
|
225 |
#openaikey.set_key(inputkey)
|
226 |
#openaikey = OpenAIKeyClass(inputkey)
|
227 |
print('ok')
|
228 |
+
if len(inputscript)>10: #有資料表示不是來自語音辨識結果
|
229 |
+
transcribe_text=inputscript
|
230 |
+
if LLMmodel=="gpt-3.5-turbo":
|
231 |
+
ainotestext=process_chunks(apikeystr,transcribe_text)
|
232 |
+
elif LLMmodel=="gpt-4-0125-preview":
|
233 |
+
ainotestext=gpt4write(apikeystr,transcribe_text)
|
234 |
+
elif LLMmodel=='gemini':
|
235 |
+
ainotestext=gewritenote(inputscript)
|
236 |
+
|
237 |
+
|
238 |
+
|
239 |
+
|
240 |
# ainotestext=inputscript
|
241 |
#ainotestext=""
|
242 |
# with open('asr_resul.txt', 'w') as f:
|
|
|
248 |
return ainotestext
|
249 |
ainotes = gr.Interface(
|
250 |
fn=writenotes,
|
251 |
+
inputs=[ gr.inputs.Radio(["gpt-3.5-turbo", "gpt-4-0125-preview","gemini"], label="LLMmodel", default="gpt-3.5-turbo"),gr.Textbox(label="使用GPT請輸入OPEN AI API KEY",placeholder="請輸入sk..."),gr.Textbox(label="逐字稿",placeholder="若沒有做語音辨識,請輸入逐字稿")],
|
252 |
outputs="text",
|
253 |
layout="horizontal",
|
254 |
theme="huggingface",
|