Spaces:
Running
Running
save and get video to gcp
Browse files- app.py +44 -30
- assets/credentials.json +13 -0
- audios/file_audio_aa99e44b-8b91-4571-a73f-25a7b701b653.wav +0 -0
app.py
CHANGED
@@ -1,22 +1,20 @@
|
|
1 |
import os
|
2 |
-
from dotenv import load_dotenv
|
3 |
import gradio as gr
|
|
|
4 |
import requests
|
5 |
import pathlib
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
load_dotenv()
|
9 |
KEY_ELEVENLABS = os.getenv('ELEVENLABS_KEY')
|
10 |
-
print(KEY_ELEVENLABS)
|
11 |
-
|
12 |
|
13 |
-
def generate_audio(text_input: str, creator: str) -> str:
|
14 |
-
CHUNK_SIZE = 1024
|
15 |
|
16 |
-
|
17 |
-
"Accept": "application/json",
|
18 |
-
"xi-api-key": KEY_ELEVENLABS
|
19 |
-
}
|
20 |
|
21 |
voice_id = ''
|
22 |
|
@@ -28,27 +26,43 @@ def generate_audio(text_input: str, creator: str) -> str:
|
|
28 |
case 'Bella':
|
29 |
voice_id = 'X9j5sAaRD6aEgBblOUOG'
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
|
54 |
app = gr.Interface(
|
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
+
import uuid
|
4 |
import requests
|
5 |
import pathlib
|
6 |
+
from elevenlabs.client import ElevenLabs, AsyncElevenLabs
|
7 |
+
from elevenlabs import play, save, Voice, stream
|
8 |
+
from dotenv import load_dotenv
|
9 |
+
from datetime import timedelta
|
10 |
+
from gcloud import storage
|
11 |
|
12 |
|
13 |
load_dotenv()
|
14 |
KEY_ELEVENLABS = os.getenv('ELEVENLABS_KEY')
|
|
|
|
|
15 |
|
|
|
|
|
16 |
|
17 |
+
async def generate_audio(text_input: str, creator: str) -> str:
|
|
|
|
|
|
|
18 |
|
19 |
voice_id = ''
|
20 |
|
|
|
26 |
case 'Bella':
|
27 |
voice_id = 'X9j5sAaRD6aEgBblOUOG'
|
28 |
|
29 |
+
CLIENT_ELEVENLABS = ElevenLabs(api_key=KEY_ELEVENLABS)
|
30 |
+
VOICE_CREATOR = Voice(voice_id=voice_id)
|
31 |
+
CREDENTIALS_GCP = os.getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
32 |
+
NAME_BUCKET = os.getenv("NAME_BUCKET")
|
33 |
+
unique_id = str(uuid.uuid4())
|
34 |
+
|
35 |
+
STORAGE_CLIENT = storage.Client.from_service_account_json(CREDENTIALS_GCP)
|
36 |
+
|
37 |
+
audio = CLIENT_ELEVENLABS.generate(
|
38 |
+
text=text_input,
|
39 |
+
voice=VOICE_CREATOR,
|
40 |
+
model="eleven_multilingual_v2"
|
41 |
+
)
|
42 |
+
|
43 |
+
source_audio_file_name = f'./audios/file_audio_{unique_id}.wav'
|
44 |
+
|
45 |
+
try:
|
46 |
+
save(audio, source_audio_file_name)
|
47 |
+
except Exception as e:
|
48 |
+
print(e)
|
49 |
+
|
50 |
+
destination_blob_name_audio = unique_id + '.wav'
|
51 |
+
|
52 |
+
bucket = STORAGE_CLIENT.bucket(NAME_BUCKET)
|
53 |
+
blob = bucket.blob(destination_blob_name_audio)
|
54 |
+
try:
|
55 |
+
blob.upload_from_filename(source_audio_file_name)
|
56 |
+
except Exception as e:
|
57 |
+
print(e)
|
58 |
+
|
59 |
+
try:
|
60 |
+
url_expiration = timedelta(minutes=15)
|
61 |
+
signed_url_audio = blob.generate_signed_url(expiration=url_expiration)
|
62 |
+
except Exception as e:
|
63 |
+
print(e)
|
64 |
+
|
65 |
+
return signed_url_audio
|
66 |
|
67 |
|
68 |
app = gr.Interface(
|
assets/credentials.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"type": "service_account",
|
3 |
+
"project_id": "bella-404621",
|
4 |
+
"private_key_id": "977139d4c3083715828cf21257ce1abe93341127",
|
5 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCzBoxMz22YIm6v\nWA8uvPLzzZbUgl8r2jp/KBAz+qKOSRmG8uH5dW3KRwuRtYLakBfjSm/+yAH3eFph\ncFK5VYEYP5o2Esg1oSO6qZC2BMEQzNOlzZmujDj9Ryz6alP6tegBfG1Nu8YRZdOS\nSkv6rRON+l9BVcZxdzWyyN9k3xis1hsxvi/o1+KT+5yl2OjKTN3H8RJ1qtQ8EJqN\nXbXbwoautZovRhQAtjMLRwEHOmKZqGttsTrhhIOwZKyzBeyzo8dwOkEhLC6q2xKi\nA+HxxN3LcHvwxIM70HF7aQSBeVsV/5QSfWOKu5oUhyvMfqwAyYfbmWKUXEWTDxbX\naoctnH57AgMBAAECggEATgIjbnDQU4NlcZhQfVAuGVhTSeRJLiWYacH+VXf4D0IB\nEpGRMA8gOQz+GI7cJvq0vgC4jm9+k+Polh7InSOJ7hQA0WEbxmqh0/uBKB8oNXbb\nHptZRPqq9opmKfPdBhjvsH4UbtPMedZB+7POKbvzEmGv0htbLiQAzRfEaALikKS6\nQqZMjCQzY0pYhx4OAkhCb0aS9xQ5+H1e/VOxQe5lnTFOZm2ugIu59aCcRP5HWDha\nzNPu6or5ZAE13H1AwoW10Vt+7rfvLshlgSvxMppL/eeNKGcx1Ufulc8ps2gBEtYA\naLZ+UOBYDVwN8ahdGF8vjQLDRzO69W0flmfQHVib+QKBgQD59Sdn5cbyVA7KpodW\ntHBIe7/dqTLVUgV1gMKdIqeCLbW5pSjcyC/ySKkxnWQiSz1oOlfIpFj6vHUJ3ZCq\nuaIysOIhpYBsYOy/oJBCP8KzoVHOOH9cPZTfvvN1ahAkiwgnhTYfZWiF5qRGjPmP\nwAMsDvh/C3kZKu4XKzGaCD9jrwKBgQC3Wm+T4RoRjrd5Whjguml/xyiW1DQSMxDF\nKI0Wt+hKmemjx8Mvgl9FSwiUInKNvMhzGBvMqzg2Hu77nLq/nc+OUbtt7gPBcJAY\ndAhAmo2FnCA2AgbvtqvFP6hGkoFsBIZaLVmQAl/4b8rlDbE+tMFgAH6R7AapnzJ/\nUqd45H1o9QKBgDL4XtS88liv82Q3mRmBKfRd574XppoBY8OWQhkw29+b2pbEqxR6\nbeyGDJplcencVeVPIF91w/89NtCQMdPejsivcS1TRmDTUvOwljosLlPa7YeT1cTF\nefo2QgcLXcdV4o/MhkDYuPu1EIKidLFvgjYVx26AtG0BaBOpZy/1xpdZAoGAMZBs\n4RjUpzJhPpiwaO97XWNFAaDTgqfzPJi9qwqD7Ma2deOmS81+W4jxBLpbJR2HQjWe\nLjGKvHaYO8QeZ3YNiXdmp0zUDxKSoUmcgXpGD3wo6PCbV2mV/Xg70PgBrGV8vBvO\nPjOmJc5yloChDUZnj8ASdvfKxUeXqvt48iEyFZECgYBh8tanHwf9itDeybhzyjjQ\n7BgI8/NEgDsTW/W+oKQurYNJiV0VRM0StVgPbMiJG7kn8sUbNGU66y1806uJ8qav\n2db9Ea/aB3HH3yDUUfNNthETO8MdmsvK/NKuRk+VVAb2My+htlzx7ah44DdrogY6\nW4RaydqELoQxBog5gvWz3A==\n-----END PRIVATE KEY-----\n",
|
6 |
+
"client_email": "link-creator@bella-404621.iam.gserviceaccount.com",
|
7 |
+
"client_id": "112531435498418864267",
|
8 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
9 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
10 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
11 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/link-creator%40bella-404621.iam.gserviceaccount.com",
|
12 |
+
"universe_domain": "googleapis.com"
|
13 |
+
}
|
audios/file_audio_aa99e44b-8b91-4571-a73f-25a7b701b653.wav
ADDED
Binary file (19.2 kB). View file
|
|