Skip to content

Commit

Permalink
Merge branch 'English' of https://github.com/philpw99/VideoCaptioner
Browse files Browse the repository at this point in the history
…into English
  • Loading branch information
philpw99 committed Jan 12, 2025
2 parents efdef47 + 2004c69 commit b2a8178
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 22 deletions.
43 changes: 43 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM python:3.10-slim-bookworm

WORKDIR /app

# 配置apt镜像源
RUN rm -rf /etc/apt/sources.list.d/* && \
rm -f /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list

# 安装系统依赖
RUN apt-get update && \
apt-get install -y \
curl \
ffmpeg \
&& rm -rf /var/lib/apt/lists/*

# 先复制依赖文件并安装
COPY streamlit_app/requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

# 复制应用代码
COPY . .

# 设置环境变量
ARG OPENAI_BASE_URL
ARG OPENAI_API_KEY
ENV OPENAI_BASE_URL=${OPENAI_BASE_URL:-https://dg.bkfeng.top/v1}
ENV OPENAI_API_KEY=${OPENAI_API_KEY}

# 创建临时目录并设置权限
RUN mkdir -p temp && chmod 777 temp

# 暴露端口
EXPOSE 8501

# 健康检查
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health

# 启动应用
ENTRYPOINT ["streamlit", "run", "streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
28 changes: 28 additions & 0 deletions app/core/bk_asr/ASRData.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,34 @@ def to_ass(self, style_str: str = None, layout: str = "Original On Top", save_pa
f.write(ass_content)
return ass_content

def to_vtt(self, save_path=None) -> str:
"""转换为WebVTT字幕格式
Args:
save_path: 可选的保存路径
Returns:
str: WebVTT格式的字幕内容
"""
# WebVTT头部
vtt_lines = ['WEBVTT\n']

for n, seg in enumerate(self.segments, 1):
# 转换时间戳格式从毫秒到 HH:MM:SS.mmm
start_time = seg._ms_to_srt_time(seg.start_time).replace(',', '.')
end_time = seg._ms_to_srt_time(seg.end_time).replace(',', '.')

# 添加序号(可选)和时间戳
vtt_lines.append(f"{n}\n{start_time} --> {end_time}\n{seg.transcript}\n")

vtt_text = "\n".join(vtt_lines)

if save_path:
with open(save_path, 'w', encoding='utf-8') as f:
f.write(vtt_text)

return vtt_text

def merge_segments(self, start_index: int, end_index: int, merged_text: str = None):
"""合并从 start_index 到 end_index 的段(包含)。"""
if start_index < 0 or end_index >= len(self.segments) or start_index > end_index:
Expand Down
2 changes: 1 addition & 1 deletion app/core/bk_asr/BaseASR.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _set_data(self):
def _get_key(self):
return f"{self.__class__.__name__}-{self.crc32_hex}"

def run(self, callback=None, **kwargs):
def run(self, callback=None, **kwargs) -> ASRData:
k = self._get_key()
if k in self.cache and self.use_cache:
resp_data = self.cache[k]
Expand Down
17 changes: 0 additions & 17 deletions app/core/bk_asr/BcutASR.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .ASRData import ASRDataSeg
from .BaseASR import BaseASR
from ..utils.logger import setup_logger
from PyQt5.QtCore import QSettings

logger = setup_logger("bcut_asr")

Expand Down Expand Up @@ -51,15 +50,6 @@ def __init__(self, audio_path: str | bytes, use_cache: bool = False, need_word_t

self.need_word_time_stamp = need_word_time_stamp

self.settings = QSettings(QSettings.IniFormat, QSettings.UserScope,
'VideoCaptioner', 'VideoCaptioner')
current_date = time.strftime('%Y-%m-%d')
last_date = self.settings.value('bcutasr/last_date', '')
if current_date != last_date:
self.settings.setValue('bcutasr/last_date', current_date)
self.settings.setValue('bcutasr/daily_calls', 0)
self.settings.sync() # 强制写入

def upload(self) -> None:
"""申请上传"""
if not self.file_binary:
Expand Down Expand Up @@ -152,13 +142,6 @@ def _run(self, callback=None, **kwargs):
if callback is None:
callback = lambda x, y: None

daily_calls = int(self.settings.value('bcutasr/daily_calls', 0))
if daily_calls >= self.MAX_DAILY_CALLS:
raise Exception(f"请明天再试")
self.settings.setValue('bcutasr/daily_calls', daily_calls + 1)
self.settings.sync() # 强制写入
print(self.settings.value('bcutasr/daily_calls', 0))

callback(0, "上传中")
self.upload()

Expand Down
5 changes: 1 addition & 4 deletions app/core/thread/transcript_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,5 @@ def progress_callback(self, value, message):

# Is the current config is using FasterWhipser and translate to English?
def isFasterWhisperTranslate(self):
if cfg.transcribe_model.value == TranscribeModelEnum.FASTER_WHISPER and cfg.faster_whisper_translate_to_english.value:
return True
else:
return False
return cfg.transcribe_model.value == TranscribeModelEnum.FASTER_WHISPER and cfg.faster_whisper_translate_to_english.value

Loading

0 comments on commit b2a8178

Please sign in to comment.