change .name to obj as is
Browse files
asr.py
CHANGED
@@ -6,6 +6,7 @@ from pathlib import Path
|
|
6 |
import torch
|
7 |
from transformers import Wav2Vec2ForCTC, AutoProcessor
|
8 |
import numpy as np
|
|
|
9 |
|
10 |
# Настройка логирования
|
11 |
logging.basicConfig(level=logging.DEBUG)
|
@@ -26,10 +27,10 @@ model = Wav2Vec2ForCTC.from_pretrained(MODEL_ID)
|
|
26 |
|
27 |
def safe_process_file(file_obj):
|
28 |
try:
|
29 |
-
logger.debug(f"Processing file: {file_obj
|
30 |
|
31 |
# Используем Path для безопасной обработки путей
|
32 |
-
file_path = Path(file_obj
|
33 |
|
34 |
logger.debug(f"Loading audio from file path: {file_path}")
|
35 |
|
@@ -61,6 +62,7 @@ def transcribe_multiple_files(audio_files, lang, transcription):
|
|
61 |
transcriptions.append(f"Error processing file: {str(e)}\n")
|
62 |
return "\n".join(transcriptions)
|
63 |
|
|
|
64 |
def transcribe_file(model, audio_samples, lang, user_transcription):
|
65 |
if not audio_samples:
|
66 |
return "<<ERROR: Empty Audio Input>>"
|
@@ -92,6 +94,7 @@ def transcribe_file(model, audio_samples, lang, user_transcription):
|
|
92 |
|
93 |
#return transcription
|
94 |
|
|
|
95 |
def fine_tune_model(model, processor, user_transcription, audio_samples, lang_code):
|
96 |
# Convert the user-provided transcription to a tensor
|
97 |
transcription_tensor = processor.tokenize(user_transcription, return_tensors="pt")
|
|
|
6 |
import torch
|
7 |
from transformers import Wav2Vec2ForCTC, AutoProcessor
|
8 |
import numpy as np
|
9 |
+
import spaces
|
10 |
|
11 |
# Настройка логирования
|
12 |
logging.basicConfig(level=logging.DEBUG)
|
|
|
27 |
|
28 |
def safe_process_file(file_obj):
|
29 |
try:
|
30 |
+
logger.debug(f"Processing file: {file_obj}")
|
31 |
|
32 |
# Используем Path для безопасной обработки путей
|
33 |
+
file_path = Path(file_obj)
|
34 |
|
35 |
logger.debug(f"Loading audio from file path: {file_path}")
|
36 |
|
|
|
62 |
transcriptions.append(f"Error processing file: {str(e)}\n")
|
63 |
return "\n".join(transcriptions)
|
64 |
|
65 |
+
@spaces.GPU
|
66 |
def transcribe_file(model, audio_samples, lang, user_transcription):
|
67 |
if not audio_samples:
|
68 |
return "<<ERROR: Empty Audio Input>>"
|
|
|
94 |
|
95 |
#return transcription
|
96 |
|
97 |
+
@spaces.GPU
|
98 |
def fine_tune_model(model, processor, user_transcription, audio_samples, lang_code):
|
99 |
# Convert the user-provided transcription to a tensor
|
100 |
transcription_tensor = processor.tokenize(user_transcription, return_tensors="pt")
|