mzltest commited on
Commit
b412759
·
1 Parent(s): b6993d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -20
app.py CHANGED
@@ -2,28 +2,43 @@ import gradio as gr
2
  import os,secrets,requests
3
  from basic_pitch.inference import predict_and_save
4
  from urllib.parse import quote
5
- os.system('chmod +x ./pget')
 
 
 
 
6
 
 
 
 
 
 
 
7
 
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
 
11
- def downloadaud(query):
12
  filename=secrets.token_hex()
13
  # Step 1: Search for videos with the given query
14
- search_url = f"https://draw-8fj.begin.app/api/search/{quote(query)}"
15
- search_response = requests.get(search_url).json()
16
- print('1=>', search_response)
17
- # Step 2: Find the first video with duration less than 10 minutes and extract its ID
18
- video_id = None
19
- #search_response = sorted(search_response, key=lambda x: x["views"], reverse=True)
20
- for item in search_response:
21
- duration = item.get("duration_raw")
22
- if duration and len(duration.split(':'))< 3 and int(duration.split(':')[0])<10:
23
- video_id = item.get("id", {}).get("videoId")
24
- break
25
- print('1-r',video_id)
26
- # If no video with duration less than 10 minutes was found, return None
27
  if not video_id:
28
  return None
29
 
@@ -51,8 +66,9 @@ def downloadaud(query):
51
  os.system(command)
52
  os.system(f'ffmpeg -i {filename}.mp4 -q:a 0 -map a {filename}.mp3')
53
  os.system(f'mv {filename}.mp3 /tmp/{filename}.mp3')
54
- res= predict(f'/tmp/{filename}.mp3')
55
- return res
 
56
 
57
 
58
  def predict(ina):
@@ -67,13 +83,18 @@ def predict(ina):
67
  )
68
  ina='.'.join(ina.split('.')[:-1])
69
 
70
- ina=ina+'_basic_pitch'
71
  os.system(f'ffmpeg -i "{ina}.wav" -f mp3 -acodec libmp3lame -y "{ina}.mp3"')
72
 
73
  return f'{fn}',f'{ina}.mp3',f'{ina}.mid'
74
- aud=gr.Textbox(label="yt query")
 
 
 
 
75
  oar=gr.Audio(label="下载的音频")
76
  oa=gr.Audio(label="预览midi")
77
  pf=gr.File(label="下载midi")
78
- demo = gr.Interface(fn=downloadaud, inputs=[aud], outputs=[oar,oa,pf])
 
79
  demo.launch()
 
2
  import os,secrets,requests
3
  from basic_pitch.inference import predict_and_save
4
  from urllib.parse import quote
5
+ import deta
6
+ from deta import Deta # Import Deta
7
+
8
+ # Initialize
9
+ deta = Deta()
10
 
11
+ # This how to connect to or create a database.
12
+ last= deta.Base("last")
13
+ records=deta.Base("records")
14
+ files=deta.Drive('music')
15
+
16
+ os.system('chmod +x ./pget')
17
 
18
 
19
+ def addrecord(orig,pitmp3,mid,gname,ghint):
20
+ if not gname or not ghint:
21
+ return 'E/缺少name或hint.'
22
+ names=gname.split('\n')
23
+ lastkey=last.get('last')
24
+ if not lastkey:
25
+ thiskey=0
26
+ else:
27
+ thiskey=lastkey['next']
28
+ #upload file src
29
+ files.put(name=orig,path=orig)
30
+ files.put(name=pitmp3,path=pitmp3)
31
+ files.put(name=mid,path=mid)
32
+ records.put({"name":names,"hint":ghint,"orig":orig,"pitmp3":pitmp3,"mid":mid},str(thiskey))
33
+ last.put({'next':thiskey+1},'last')
34
+ return 'OK'
35
+
36
 
37
 
38
+ def downloadaud(video_id,gname,ghint):
39
  filename=secrets.token_hex()
40
  # Step 1: Search for videos with the given query
41
+
 
 
 
 
 
 
 
 
 
 
 
 
42
  if not video_id:
43
  return None
44
 
 
66
  os.system(command)
67
  os.system(f'ffmpeg -i {filename}.mp4 -q:a 0 -map a {filename}.mp3')
68
  os.system(f'mv {filename}.mp3 /tmp/{filename}.mp3')
69
+ o,m,i= predict(f'/tmp/{filename}.mp3')
70
+ res=addrecord(o,m,i,gname,ghint)
71
+ return o,m,i,res
72
 
73
 
74
  def predict(ina):
 
83
  )
84
  ina='.'.join(ina.split('.')[:-1])
85
 
86
+ ina=ina+'_t_'
87
  os.system(f'ffmpeg -i "{ina}.wav" -f mp3 -acodec libmp3lame -y "{ina}.mp3"')
88
 
89
  return f'{fn}',f'{ina}.mp3',f'{ina}.mid'
90
+
91
+
92
+ aud=gr.Textbox(label="视频ID")
93
+ g_name=gr.Textarea(label="游戏名称(谜底),回车分名称,一行一个,最多20个")
94
+ g_hint=gr.Textarea(label="开发厂商(提示)")
95
  oar=gr.Audio(label="下载的音频")
96
  oa=gr.Audio(label="预览midi")
97
  pf=gr.File(label="下载midi")
98
+ res=gr.Textbox(label="结果")
99
+ demo = gr.Interface(fn=downloadaud, inputs=[aud,g_name,g_hint], outputs=[oar,oa,pf,res])
100
  demo.launch()