Spaces:
Running
Running
system_message = "你是專業的 LATEX 轉換師,擅長將數學符號、公式轉換成 LATEX 格式"
Browse files
app.py
CHANGED
@@ -2449,15 +2449,29 @@ def process_open_ai_audio_to_chatbot(password, audio_url):
|
|
2449 |
if file_size > 2000000:
|
2450 |
raise gr.Error("檔案大小超過,請不要超過 60秒")
|
2451 |
else:
|
2452 |
-
|
2453 |
model="whisper-1",
|
2454 |
file=audio_file,
|
2455 |
response_format="text"
|
2456 |
)
|
2457 |
# response 拆解 dict
|
2458 |
-
print("===
|
2459 |
-
print(
|
2460 |
-
print("===
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2461 |
else:
|
2462 |
response = ""
|
2463 |
|
|
|
2449 |
if file_size > 2000000:
|
2450 |
raise gr.Error("檔案大小超過,請不要超過 60秒")
|
2451 |
else:
|
2452 |
+
transcription = OPEN_AI_CLIENT.audio.transcriptions.create(
|
2453 |
model="whisper-1",
|
2454 |
file=audio_file,
|
2455 |
response_format="text"
|
2456 |
)
|
2457 |
# response 拆解 dict
|
2458 |
+
print("=== transcription ===")
|
2459 |
+
print(transcription)
|
2460 |
+
print("=== transcription ===")
|
2461 |
+
# 確認 response 是否有數學符號,prompt to LATEX $... $, ex: $x^2$
|
2462 |
+
|
2463 |
+
if transcription:
|
2464 |
+
system_message = "你是專業的 LATEX 轉換師,擅長將數學符號、公式轉換成 LATEX 格式"
|
2465 |
+
user_message = transcription
|
2466 |
+
request = OPEN_AI_CLIENT.chat.completions.create(
|
2467 |
+
model="gpt-4-turbo",
|
2468 |
+
messages=[
|
2469 |
+
{"role": "system", "content": system_message},
|
2470 |
+
{"role": "user", "content": user_message}
|
2471 |
+
],
|
2472 |
+
max_tokens=4000,
|
2473 |
+
)
|
2474 |
+
response = request.choices[0].message.content.strip()
|
2475 |
else:
|
2476 |
response = ""
|
2477 |
|