Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【修复】Workaround for crash on Windows #37

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions project/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import streamlit as st
import streamlit_antd_components as sac
from openai import OpenAI
from .utils.utils2 import (openai_whisper_result, faster_whisper_result, file_to_mp3, check_ffmpeg, check_cuda_support)
from .utils.utils2 import (openai_whisper_result, runWhisperSeperateProc, file_to_mp3, check_ffmpeg, check_cuda_support)


def content():
Expand Down Expand Up @@ -203,7 +203,7 @@ def content():
model = faster_whisper_model
if faster_whisper_local:
model = faster_whisper_local_path
result = faster_whisper_result(output_file, device, model, "Don’t make each line too long.", temperature_setting, False, "自动识别", beam_size_setting, 500)
result = runWhisperSeperateProc(output_file, device, model, "Don’t make each line too long.", temperature_setting, False, "自动识别", beam_size_setting, 500)
st.session_state.text = result["text"]
st.toast("已识别完成,开始对话叭!", icon=":material/task_alt:")
else:
Expand Down
8 changes: 4 additions & 4 deletions project/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import datetime
import streamlit as st
import streamlit_antd_components as sac
from project.utils.utils2 import (file_to_mp3, openai_whisper_result, faster_whisper_result, translate, local_translate,
from project.utils.utils2 import (file_to_mp3, openai_whisper_result, runWhisperSeperateProc, translate, local_translate,
generate_srt_from_result, generate_srt_from_result_2, srt_mv, show_video, parse_srt_file,
convert_to_srt, srt_to_ass, srt_to_stl, srt_to_vtt, check_cuda_support, check_ffmpeg,
add_font_settings)
Expand Down Expand Up @@ -391,7 +391,7 @@ def media():
model = faster_whisper_model
if faster_whisper_local:
model = faster_whisper_local_path
result = faster_whisper_result(output_file1, device, model, whisper_prompt_setting, temperature_setting, vad_setting, lang_setting, beam_size_setting, min_vad_setting)
result = runWhisperSeperateProc(output_file1, device, model, whisper_prompt_setting, temperature_setting, vad_setting, lang_setting, beam_size_setting, min_vad_setting)

time3 = time.time()
translation_dict = {
Expand Down Expand Up @@ -526,7 +526,7 @@ def media():
model = faster_whisper_model
if faster_whisper_local:
model = faster_whisper_local_path
result = faster_whisper_result(output_file, device, model, whisper_prompt_setting, temperature_setting, vad_setting, lang_setting, beam_size_setting, min_vad_setting)
result = runWhisperSeperateProc(output_file, device, model, whisper_prompt_setting, temperature_setting, vad_setting, lang_setting, beam_size_setting, min_vad_setting)

time3 = time.time()
translation_dict = {
Expand Down Expand Up @@ -635,7 +635,7 @@ def media():
model = faster_whisper_model
if faster_whisper_local:
model = faster_whisper_local_path
result = faster_whisper_result(output_file, device, model, whisper_prompt_setting, temperature_setting, vad_setting, lang_setting, beam_size_setting, min_vad_setting)
result = runWhisperSeperateProc(output_file, device, model, whisper_prompt_setting, temperature_setting, vad_setting, lang_setting, beam_size_setting, min_vad_setting)

time3 = time.time()
translation_dict = {
Expand Down
15 changes: 13 additions & 2 deletions project/utils/utils2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from multiprocessing import Process, Manager
import os
import re
import math
Expand Down Expand Up @@ -114,7 +115,7 @@ def openai_whisper_result(key, base, path, prompt, temperature):
return result


def faster_whisper_result(file_path, device, model_name, prompt, temp, vad, lang, beam_size, min_vad):
def faster_whisper_result(file_path, device, model_name, prompt, temp, vad, lang, beam_size, min_vad, returnList):
if model_name not in ['tiny', 'tiny.en', 'base', 'base.en', 'small', 'small.en', 'medium', 'medium.en', 'large-v1',
'large-v2', 'large-v3', 'large', 'distil-small.en', 'distil-medium.en', 'distil-large-v2',
'distil-large-v3']:
Expand Down Expand Up @@ -165,7 +166,17 @@ def faster_whisper_result(file_path, device, model_name, prompt, temp, vad, lang

result = faster_whisper_result_dict(segments)
print(f"- whisper识别内容:\n{result['text']}\n")
return result
returnList[0] = result


def runWhisperSeperateProc(*args):
with Manager() as manager:
returnList = manager.list([None])
p = Process(target=faster_whisper_result, args=args + (returnList,))
p.start()
p.join()
p.close()
return returnList[0]


def translate(system_prompt, user_prompt, api_key, base_url, model, result, wait_time, srt):
Expand Down