Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import librosa
|
|
3 |
import numpy as np
|
4 |
import torch
|
5 |
import string
|
6 |
-
import
|
7 |
|
8 |
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
9 |
|
@@ -28,8 +28,25 @@ translator = Translator()
|
|
28 |
def convert_number_to_words(number: float) -> str:
|
29 |
p = inflect.engine()
|
30 |
words = p.number_to_words(number)
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def process_text(text: str) -> str:
|
35 |
# Convert numbers to words
|
|
|
3 |
import numpy as np
|
4 |
import torch
|
5 |
import string
|
6 |
+
import httpx
|
7 |
|
8 |
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
9 |
|
|
|
28 |
def convert_number_to_words(number: float) -> str:
|
29 |
p = inflect.engine()
|
30 |
words = p.number_to_words(number)
|
31 |
+
|
32 |
+
# Translate using httpx
|
33 |
+
async def translate_text(text, source_lang, target_lang):
|
34 |
+
async with httpx.AsyncClient() as client:
|
35 |
+
response = await client.get(
|
36 |
+
f'https://api.mymemory.translated.net/get?q={text}&langpair={source_lang}|{target_lang}'
|
37 |
+
)
|
38 |
+
translation = response.json()
|
39 |
+
return translation['responseData']['translatedText']
|
40 |
+
|
41 |
+
# You can change 'en' to the appropriate source language code
|
42 |
+
source_lang = 'en'
|
43 |
+
# You can change 'hy' to the appropriate target language code
|
44 |
+
target_lang = 'hy'
|
45 |
+
|
46 |
+
# Perform translation asynchronously
|
47 |
+
translated_words = httpx.run(translate_text, words, source_lang, target_lang)
|
48 |
+
|
49 |
+
return translated_words
|
50 |
|
51 |
def process_text(text: str) -> str:
|
52 |
# Convert numbers to words
|