Spaces:
Sleeping
Sleeping
add summary
Browse files
app.py
CHANGED
@@ -41,6 +41,24 @@ def call_openai_api(openaiobj,transcription):
|
|
41 |
]
|
42 |
)
|
43 |
return response.choices[0].message.content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
|
46 |
def split_into_chunks(text, tokens=3500):
|
@@ -70,8 +88,11 @@ def process_chunks(openaikeystr,inputtext):
|
|
70 |
chunks = split_into_chunks(text)
|
71 |
response=''
|
72 |
for chunk in chunks:
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
75 |
# # Processes chunks in parallel
|
76 |
# with ThreadPoolExecutor() as executor:
|
77 |
# responses = list(executor.map(call_openai_api, [openaiobj,chunks]))
|
@@ -188,7 +209,8 @@ def writenotes( apikeystr,inputscript):
|
|
188 |
print('ok')
|
189 |
if len(inputscript)>10:
|
190 |
transcribe_text=inputscript
|
191 |
-
|
|
|
192 |
# ainotestext=inputscript
|
193 |
#ainotestext=""
|
194 |
# with open('asr_resul.txt', 'w') as f:
|
@@ -200,13 +222,13 @@ def writenotes( apikeystr,inputscript):
|
|
200 |
return ainotestext
|
201 |
ainotes = gr.Interface(
|
202 |
fn=writenotes,
|
203 |
-
inputs=[gr.Textbox(label="OPEN AI API KEY",placeholder="請輸入sk..."),gr.Textbox(label="逐字稿",placeholder="
|
204 |
outputs="text",
|
205 |
layout="horizontal",
|
206 |
theme="huggingface",
|
207 |
title="會議紀錄小幫手AINotes",
|
208 |
description=(
|
209 |
-
"
|
210 |
f" 使用這個模型 [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) 先做語音辨識再做會議紀錄摘要"
|
211 |
" 長度沒有限制"
|
212 |
),
|
|
|
41 |
]
|
42 |
)
|
43 |
return response.choices[0].message.content
|
44 |
+
def call_openai_summary(openaiobj,transcription):
|
45 |
+
|
46 |
+
response = openaiobj.chat.completions.create(
|
47 |
+
model="gpt-3.5-turbo",
|
48 |
+
temperature=0,
|
49 |
+
messages=[
|
50 |
+
{
|
51 |
+
"role": "system",
|
52 |
+
"content": "你是專業的文書處理員,請根據由語音辨識軟體將會議錄音所轉錄的逐字稿,摘錄重點,要用比較正式及容易閱讀的寫法,避免口語化"
|
53 |
+
},
|
54 |
+
{
|
55 |
+
"role": "user",
|
56 |
+
"content": transcription
|
57 |
+
}
|
58 |
+
]
|
59 |
+
)
|
60 |
+
return response.choices[0].message.content
|
61 |
+
|
62 |
|
63 |
|
64 |
def split_into_chunks(text, tokens=3500):
|
|
|
88 |
chunks = split_into_chunks(text)
|
89 |
response=''
|
90 |
for chunk in chunks:
|
91 |
+
#response=response+call_openai_api(openaiobj,chunk)
|
92 |
+
response=response+call_openai_summary(openaiobj,chunk)
|
93 |
+
|
94 |
+
finalresponse=response+' summary \n\n' +call_openai_api(openaiobj,response)
|
95 |
+
return finalresponse
|
96 |
# # Processes chunks in parallel
|
97 |
# with ThreadPoolExecutor() as executor:
|
98 |
# responses = list(executor.map(call_openai_api, [openaiobj,chunks]))
|
|
|
209 |
print('ok')
|
210 |
if len(inputscript)>10:
|
211 |
transcribe_text=inputscript
|
212 |
+
|
213 |
+
ainotestext=process_chunks(apikeystr,transcribe_text)
|
214 |
# ainotestext=inputscript
|
215 |
#ainotestext=""
|
216 |
# with open('asr_resul.txt', 'w') as f:
|
|
|
222 |
return ainotestext
|
223 |
ainotes = gr.Interface(
|
224 |
fn=writenotes,
|
225 |
+
inputs=[gr.Textbox(label="OPEN AI API KEY",placeholder="請輸入sk..."),gr.Textbox(label="逐字稿",placeholder="若沒有做語音辨識,請輸入逐字稿")],
|
226 |
outputs="text",
|
227 |
layout="horizontal",
|
228 |
theme="huggingface",
|
229 |
title="會議紀錄小幫手AINotes",
|
230 |
description=(
|
231 |
+
"可由麥克風錄音或上傳語音檔若有逐字稿可以直接貼在逐字稿"
|
232 |
f" 使用這個模型 [{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) 先做語音辨識再做會議紀錄摘要"
|
233 |
" 長度沒有限制"
|
234 |
),
|