Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -5,6 +5,7 @@ from googletrans import Translator
|
|
5 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
6 |
from fastapi.responses import JSONResponse
|
7 |
from pathlib import Path
|
|
|
8 |
|
9 |
app = FastAPI()
|
10 |
|
@@ -44,12 +45,16 @@ async def process_audio(file: UploadFile = File(...)):
|
|
44 |
with open(file_location, "wb") as saved_file:
|
45 |
saved_file.write(file.file.read())
|
46 |
|
|
|
|
|
|
|
|
|
47 |
# JP
|
48 |
-
original = pipe(
|
49 |
original_version = original["text"]
|
50 |
|
51 |
# EN
|
52 |
-
result = pipe(
|
53 |
hasil = result["text"]
|
54 |
|
55 |
# ID
|
@@ -96,4 +101,4 @@ def modify_text(text):
|
|
96 |
for original, replacement in replacements.items():
|
97 |
text = text.replace(original, replacement)
|
98 |
|
99 |
-
return text
|
|
|
5 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
6 |
from fastapi.responses import JSONResponse
|
7 |
from pathlib import Path
|
8 |
+
import numpy as np
|
9 |
|
10 |
app = FastAPI()
|
11 |
|
|
|
45 |
with open(file_location, "wb") as saved_file:
|
46 |
saved_file.write(file.file.read())
|
47 |
|
48 |
+
# Read audio file and convert to NumPy ndarray
|
49 |
+
audio_array, _ = torchaudio.load(file_location, normalize=True)
|
50 |
+
audio_array = np.array(audio_array[0].numpy())
|
51 |
+
|
52 |
# JP
|
53 |
+
original = pipe(audio_array)
|
54 |
original_version = original["text"]
|
55 |
|
56 |
# EN
|
57 |
+
result = pipe(audio_array, generate_kwargs={"task": "translate"})
|
58 |
hasil = result["text"]
|
59 |
|
60 |
# ID
|
|
|
101 |
for original, replacement in replacements.items():
|
102 |
text = text.replace(original, replacement)
|
103 |
|
104 |
+
return text
|