lihaoxin2020 commited on
Commit
4e42c1a
·
1 Parent(s): ade1cce
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -166,6 +166,16 @@ def kotoba_speech_tts(text):
166
  print(parsed_dir)
167
  return parsed_dir
168
 
 
 
 
 
 
 
 
 
 
 
169
  ####################################
170
  # Space initialization
171
  ####################################
@@ -676,6 +686,14 @@ def synthandreturn(text):
676
  result = router.predict(*model_args[model], **model_kwargs[model])
677
  else:
678
  result = kotoba_speech_tts(text)
 
 
 
 
 
 
 
 
679
  else:
680
  # result = router.predict(text, model.lower(), api_name="/synthesize")
681
  # result = router.predict(
 
166
  print(parsed_dir)
167
  return parsed_dir
168
 
169
+ def download_file(url, local_filename):
170
+ # Make a GET request to the URL
171
+ with requests.get(url, stream=True) as response:
172
+ response.raise_for_status() # Raise an error for bad status codes
173
+ # Open a local file with write-binary mode
174
+ with open(local_filename, 'wb') as f:
175
+ for chunk in response.iter_content(chunk_size=8192):
176
+ f.write(chunk)
177
+ return local_filename
178
+
179
  ####################################
180
  # Space initialization
181
  ####################################
 
686
  result = router.predict(*model_args[model], **model_kwargs[model])
687
  else:
688
  result = kotoba_speech_tts(text)
689
+ # URL to download the file from
690
+ url = f"https://kotoba-tech-kotoba-speech.hf.space/file={result}"
691
+ # Local filename to save the downloaded file
692
+ local_filename = result
693
+
694
+ # Call the function to download the file
695
+ downloaded_file = download_file(url, local_filename)
696
+ print(f"File downloaded as: {downloaded_file}")
697
  else:
698
  # result = router.predict(text, model.lower(), api_name="/synthesize")
699
  # result = router.predict(