add latex
This commit is contained in:
24
services/convertMdToPdf.py
Normal file
24
services/convertMdToPdf.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import re
|
||||
from pylatexenc.latex2text import LatexNodes2Text
|
||||
|
||||
class ConvertMdToPdf:
|
||||
# Конвертирует md в pdf
|
||||
def convertLatexToText(self, text:str):
|
||||
# Обрабатываем только математические выражения
|
||||
text = re.sub(
|
||||
r'\$\$(.*?)\$\$|\$(.*?)\$',
|
||||
self.replace_math,
|
||||
text,
|
||||
flags=re.DOTALL
|
||||
)
|
||||
return text
|
||||
|
||||
def replace_math(self, match):
|
||||
math_content = match.group(1) or match.group(2) # $$...$$ или $...$
|
||||
try:
|
||||
# Преобразуем только математическое выражение
|
||||
converted = LatexNodes2Text().latex_to_text(math_content)
|
||||
return converted
|
||||
except:
|
||||
return math_content # В случае ошибки оставляем как есть
|
||||
|
||||
@@ -2,7 +2,7 @@ from faster_whisper import WhisperModel
|
||||
|
||||
class FasterWhisper:
|
||||
def recognize(self, model, audioFile, beamSize, vadFilter, minSilenceDurationMs, speechPadMs, temp0, temp1, temp2, wordTimestamps, noSpeechThreshold, conditionOnPreviousText):
|
||||
model = WhisperModel(model, device='cuda', compute_type='float16') # Задаем модель
|
||||
model = WhisperModel(model, device='auto', compute_type='auto') # Задаем модель
|
||||
|
||||
segments, _ = model.transcribe( # Распознаем текст
|
||||
audioFile,
|
||||
@@ -32,5 +32,3 @@ class FasterWhisper:
|
||||
seconds_int = (millis % (60 * 1000)) // 1000
|
||||
millis = millis % 1000
|
||||
return f"{hours:02d}:{minutes:02d}:{seconds_int:02d},{millis:03d}"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user