Spaces:
Running
Running
clementruhm
commited on
Commit
·
8ca90cb
1
Parent(s):
7200272
Update app.py
Browse files
app.py
CHANGED
@@ -11,8 +11,9 @@ import socket
|
|
11 |
from typing import Dict
|
12 |
|
13 |
import gradio as gr
|
|
|
14 |
|
15 |
-
from vc_service_request import vc_service_request
|
16 |
|
17 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
18 |
counter = 0
|
@@ -21,6 +22,9 @@ counter = 0
|
|
21 |
users: Dict[str, int] = {}
|
22 |
FREE_TIER = 5
|
23 |
|
|
|
|
|
|
|
24 |
|
25 |
def get_ip(request: gr.Request) -> str:
|
26 |
"""
|
@@ -64,9 +68,10 @@ def main():
|
|
64 |
|
65 |
Here's how it works:
|
66 |
|
67 |
-
1.
|
68 |
-
2.
|
69 |
-
3.
|
|
|
70 |
|
71 |
If providing your own audio files, please use WAVE PCM.
|
72 |
Service works with 16kHz, 16 bit, mono audio.
|
@@ -118,7 +123,7 @@ def main():
|
|
118 |
if not src_ or not tgt_:
|
119 |
logging.warning("source or target are not provided")
|
120 |
return
|
121 |
-
global counter, users
|
122 |
ip_ = get_ip(request_)
|
123 |
past_requests_ = users.get(ip_, 0)
|
124 |
free_tier_ = False
|
@@ -128,7 +133,7 @@ def main():
|
|
128 |
api_secret_ = os.environ["api_secret"]
|
129 |
if free_tier and past_requests_ >= FREE_TIER:
|
130 |
logging.info(f"Free tier exceeded for {ip_}")
|
131 |
-
return
|
132 |
logging.info(f"Total number of requests: {counter}. {past_requests_} for {ip_}")
|
133 |
counter += 1
|
134 |
users[ip_] = past_requests_ + 1
|
|
|
11 |
from typing import Dict
|
12 |
|
13 |
import gradio as gr
|
14 |
+
import soundfile as sf
|
15 |
|
16 |
+
from vc_service_request import vc_service_request, prepare_audio
|
17 |
|
18 |
script_dir = os.path.dirname(os.path.abspath(__file__))
|
19 |
counter = 0
|
|
|
22 |
users: Dict[str, int] = {}
|
23 |
FREE_TIER = 5
|
24 |
|
25 |
+
data, fs = sf.read(os.path.join(script_dir, "free_tier.wav"))
|
26 |
+
audio_msg = prepare_audio((fs, data))
|
27 |
+
|
28 |
|
29 |
def get_ip(request: gr.Request) -> str:
|
30 |
"""
|
|
|
68 |
|
69 |
Here's how it works:
|
70 |
|
71 |
+
1. Provide your credentials (API key and secret) or leave fields blank to use free tier.
|
72 |
+
2. Begin by recording your voice.
|
73 |
+
3. Select an audio sample that represents the target voice you want to convert to.
|
74 |
+
4. Click the "Convert" button and listen to the result!
|
75 |
|
76 |
If providing your own audio files, please use WAVE PCM.
|
77 |
Service works with 16kHz, 16 bit, mono audio.
|
|
|
123 |
if not src_ or not tgt_:
|
124 |
logging.warning("source or target are not provided")
|
125 |
return
|
126 |
+
global counter, users, audio_msg
|
127 |
ip_ = get_ip(request_)
|
128 |
past_requests_ = users.get(ip_, 0)
|
129 |
free_tier_ = False
|
|
|
133 |
api_secret_ = os.environ["api_secret"]
|
134 |
if free_tier and past_requests_ >= FREE_TIER:
|
135 |
logging.info(f"Free tier exceeded for {ip_}")
|
136 |
+
return 16000, audio_msg
|
137 |
logging.info(f"Total number of requests: {counter}. {past_requests_} for {ip_}")
|
138 |
counter += 1
|
139 |
users[ip_] = past_requests_ + 1
|