Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -32,35 +32,44 @@ MODELS_PATH = os.getenv("MODELS_PATH", "./pretrained_models")
|
|
32 |
os.makedirs(MODELS_PATH, exist_ok=True)
|
33 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
response.
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
def get_random_string():
|
66 |
return "".join(str(uuid.uuid4()).split("-"))
|
|
|
32 |
os.makedirs(MODELS_PATH, exist_ok=True)
|
33 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
34 |
|
35 |
+
if not os.path.exists(os.path.join(MODELS_PATH, "wmencodec.th")):
|
36 |
+
# download wmencodec
|
37 |
+
url = "https://huggingface.co/westbrook/SSR-Speech-English/resolve/main/wmencodec.th"
|
38 |
+
filename = os.path.join(MODELS_PATH, "wmencodec.th")
|
39 |
+
response = requests.get(url, stream=True)
|
40 |
+
response.raise_for_status()
|
41 |
+
with open(filename, "wb") as file:
|
42 |
+
for chunk in response.iter_content(chunk_size=8192):
|
43 |
+
file.write(chunk)
|
44 |
+
print(f"File downloaded to: {filename}")
|
45 |
+
else:
|
46 |
+
print("wmencodec model found")
|
47 |
+
|
48 |
+
if not os.path.exists(os.path.join(MODELS_PATH, "English.pth")):
|
49 |
+
# download english model
|
50 |
+
url = "https://huggingface.co/westbrook/SSR-Speech-English/resolve/main/English.pth"
|
51 |
+
filename = os.path.join(MODELS_PATH, "English.pth")
|
52 |
+
response = requests.get(url, stream=True)
|
53 |
+
response.raise_for_status()
|
54 |
+
with open(filename, "wb") as file:
|
55 |
+
for chunk in response.iter_content(chunk_size=8192):
|
56 |
+
file.write(chunk)
|
57 |
+
print(f"File downloaded to: {filename}")
|
58 |
+
else:
|
59 |
+
print("english model found")
|
60 |
+
|
61 |
+
if not os.path.exists(os.path.join(MODELS_PATH, "Mandarin.pth")):
|
62 |
+
# download mandarin model
|
63 |
+
url = "https://huggingface.co/westbrook/SSR-Speech-Mandarin/resolve/main/Mandarin.pth"
|
64 |
+
filename = os.path.join(MODELS_PATH, "Mandarin.pth")
|
65 |
+
response = requests.get(url, stream=True)
|
66 |
+
response.raise_for_status()
|
67 |
+
with open(filename, "wb") as file:
|
68 |
+
for chunk in response.iter_content(chunk_size=8192):
|
69 |
+
file.write(chunk)
|
70 |
+
print(f"File downloaded to: {filename}")
|
71 |
+
else:
|
72 |
+
print("mandarin model found")
|
73 |
|
74 |
def get_random_string():
|
75 |
return "".join(str(uuid.uuid4()).split("-"))
|