Update app.py
Browse files
app.py
CHANGED
|
@@ -6,12 +6,25 @@ from huggingface_hub import login
|
|
| 6 |
from scipy.io.wavfile import write
|
| 7 |
import uuid
|
| 8 |
import torch
|
|
|
|
| 9 |
|
| 10 |
print("cuda", torch.cuda.is_available())
|
| 11 |
|
| 12 |
access_token_read = os.environ.get('HF_TOKEN', None)
|
|
|
|
|
|
|
|
|
|
| 13 |
login(token = access_token_read)
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
print("cur path", os.listdir(os.path.join("..", "..", "..")))
|
| 16 |
|
| 17 |
if not os.path.isdir(os.path.join("..", "..", "..", "data", "hfcache")):
|
|
@@ -40,10 +53,10 @@ def transcribe(audio):
|
|
| 40 |
text = text.replace("à la ligne", "\n")
|
| 41 |
text = text.replace(" virgule", ",")
|
| 42 |
text = text.replace(" virgule", ",")
|
| 43 |
-
text = text.replace(" point", ".")
|
| 44 |
-
text = text.replace(" point", ".")
|
| 45 |
text = text.replace(" deux points", ":")
|
| 46 |
text = text.replace(" deux points", ":")
|
|
|
|
|
|
|
| 47 |
text = text.replace(" nouveau paragraphe ", "\n\n")
|
| 48 |
text = text.replace(" paragraphe ", "\n\n")
|
| 49 |
|
|
@@ -56,10 +69,13 @@ def save_fn(audio, text):
|
|
| 56 |
|
| 57 |
uid = str(uuid.uuid4())
|
| 58 |
|
| 59 |
-
with open(
|
| 60 |
f.write(text)
|
|
|
|
| 61 |
|
| 62 |
-
write(
|
|
|
|
|
|
|
| 63 |
return [None, ""]
|
| 64 |
|
| 65 |
with gr.Blocks() as demo:
|
|
|
|
| 6 |
from scipy.io.wavfile import write
|
| 7 |
import uuid
|
| 8 |
import torch
|
| 9 |
+
import boto3
|
| 10 |
|
| 11 |
print("cuda", torch.cuda.is_available())
|
| 12 |
|
| 13 |
access_token_read = os.environ.get('HF_TOKEN', None)
|
| 14 |
+
access_key = os.environ.get('access_key', None)
|
| 15 |
+
secret_access_key = os.environ.get('secret_access_key', None)
|
| 16 |
+
|
| 17 |
login(token = access_token_read)
|
| 18 |
|
| 19 |
+
session = boto3.Session(
|
| 20 |
+
aws_access_key_id=access_key,
|
| 21 |
+
aws_secret_access_key=secret_access_key,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
s3 = session.resource('s3')
|
| 25 |
+
|
| 26 |
+
BUCKET = "audio-text-938"
|
| 27 |
+
|
| 28 |
print("cur path", os.listdir(os.path.join("..", "..", "..")))
|
| 29 |
|
| 30 |
if not os.path.isdir(os.path.join("..", "..", "..", "data", "hfcache")):
|
|
|
|
| 53 |
text = text.replace("à la ligne", "\n")
|
| 54 |
text = text.replace(" virgule", ",")
|
| 55 |
text = text.replace(" virgule", ",")
|
|
|
|
|
|
|
| 56 |
text = text.replace(" deux points", ":")
|
| 57 |
text = text.replace(" deux points", ":")
|
| 58 |
+
text = text.replace(" point", ".")
|
| 59 |
+
text = text.replace(" point", ".")
|
| 60 |
text = text.replace(" nouveau paragraphe ", "\n\n")
|
| 61 |
text = text.replace(" paragraphe ", "\n\n")
|
| 62 |
|
|
|
|
| 69 |
|
| 70 |
uid = str(uuid.uuid4())
|
| 71 |
|
| 72 |
+
with open(f"{uid}.txt"), "w", encoding="utf-8") as f:
|
| 73 |
f.write(text)
|
| 74 |
+
s3.Bucket(BUCKET).upload_file(f"{uid}.txt", f"texts/{uid}.txt") #local path, bucket path
|
| 75 |
|
| 76 |
+
write(f"{uid}.wav", sr, y)
|
| 77 |
+
s3.Bucket(BUCKET).upload_file(f"{uid}.wav", f"audios/{uid}.wav") #local path, bucket path
|
| 78 |
+
|
| 79 |
return [None, ""]
|
| 80 |
|
| 81 |
with gr.Blocks() as demo:
|