Spaces:
Runtime error
Runtime error
add Dockerfile
Browse files- app.py +35 -0
- requirements.txt +8 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoProcessor, SeamlessM4Tv2Model
|
2 |
+
import numpy as np
|
3 |
+
#import torchaudio
|
4 |
+
import sounddevice as sd
|
5 |
+
#from audio
|
6 |
+
|
7 |
+
processor = AutoProcessor.from_pretrained("facebook/seamless-m4t-v2-large")
|
8 |
+
model = SeamlessM4Tv2Model.from_pretrained("facebook/seamless-m4t-v2-large")
|
9 |
+
|
10 |
+
# from text
|
11 |
+
text_inputs = processor(text = "Искам da polucha zdravnata mi karta i помощ", src_lang="bul", return_tensors="pt")
|
12 |
+
audio_array_from_text = model.generate(**text_inputs, tgt_lang="fra")[0].cpu().numpy().squeeze()
|
13 |
+
|
14 |
+
# Afficher le tableau dans le terminal
|
15 |
+
print(audio_array_from_text)
|
16 |
+
|
17 |
+
# Optionnel : Afficher seulement les 10 premières valeurs pour éviter trop de sorties
|
18 |
+
print(audio_array_from_text[:10])
|
19 |
+
|
20 |
+
sd.play(audio_array_from_text, samplerate=16000) # 16kHz est souvent utilisé par ces modèles
|
21 |
+
sd.wait()
|
22 |
+
|
23 |
+
|
24 |
+
audio, orig_freq = torchaudio.load("https://www2.cs.uic.edu/~i101/SoundFiles/preamble10.wav")
|
25 |
+
# audio = torchaudio.functional.resample(audio, orig_freq=orig_freq, new_freq=16_000) # must be a 16 kHz waveform array
|
26 |
+
# audio_inputs = processor(audios=audio, return_tensors="pt")
|
27 |
+
# audio_array_from_audio = model.generate(**audio_inputs, tgt_lang="rus")[0].cpu().numpy().squeeze()
|
28 |
+
|
29 |
+
# from audio
|
30 |
+
output_tokens = model.generate(**audio_inputs, tgt_lang="fra", generate_speech=False)
|
31 |
+
translated_text_from_audio = processor.decode(output_tokens[0].tolist()[0], skip_special_tokens=True)
|
32 |
+
|
33 |
+
# from text
|
34 |
+
output_tokens = model.generate(**text_inputs, tgt_lang="fra", generate_speech=False)
|
35 |
+
translated_text_from_text = processor.decode(output_tokens[0].tolist()[0], skip_special_tokens=True)
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Flask==2.0.3
|
2 |
+
mlx
|
3 |
+
mlx-lm
|
4 |
+
|
5 |
+
transformers==4.11.3
|
6 |
+
datasets==1.15.1
|
7 |
+
huggingface-hub==0.1.0
|
8 |
+
matplotlib==3.4.3
|