admin commited on
Commit
9f2c3ca
·
1 Parent(s): 9d68b29

use gradio tmp as mp3 cache dir

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  import re
3
  import json
 
4
  import torch
5
  import shutil
6
  import requests
@@ -99,10 +100,8 @@ def music163_song_info(id: str):
99
  def url_infer(song: str, cache_dir="./__pycache__/mode2"):
100
  song_name = ""
101
  clean_cache(cache_dir)
102
- audio_path = "./__pycache__/output.mp3"
103
- if os.path.exists(audio_path):
104
- os.remove(audio_path)
105
-
106
  try:
107
  if (is_url(song) and "163" in song and "?id=" in song) or song.isdigit():
108
  song_id = get_1st_int(song.split("?id=")[-1])
@@ -111,6 +110,7 @@ def url_infer(song: str, cache_dir="./__pycache__/mode2"):
111
  if not free:
112
  raise AttributeError("Unable to parse VIP songs")
113
 
 
114
  download_audio(song_url, audio_path)
115
 
116
  midi, title = audio2midi(audio_path, cache_dir)
 
1
  import os
2
  import re
3
  import json
4
+ import uuid
5
  import torch
6
  import shutil
7
  import requests
 
100
  def url_infer(song: str, cache_dir="./__pycache__/mode2"):
101
  song_name = ""
102
  clean_cache(cache_dir)
103
+ audio_path = f"/tmp/gradio/{uuid.uuid4().hex}/"
104
+ os.makedirs(audio_path, exist_ok=True)
 
 
105
  try:
106
  if (is_url(song) and "163" in song and "?id=" in song) or song.isdigit():
107
  song_id = get_1st_int(song.split("?id=")[-1])
 
110
  if not free:
111
  raise AttributeError("Unable to parse VIP songs")
112
 
113
+ audio_path += f"{song_id}.mp3"
114
  download_audio(song_url, audio_path)
115
 
116
  midi, title = audio2midi(audio_path, cache_dir)