Omnibus commited on
Commit
6431362
1 Parent(s): 816344b

Update player.py

Browse files
Files changed (1) hide show
  1. player.py +61 -1
player.py CHANGED
@@ -18,7 +18,65 @@ def find_dataset(author=""):
18
  pass
19
  return (gr.Dropdown(label="Channels", choices=[s for s in channels],interactive=True))
20
 
 
21
  def load_vid(channel):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  out_html=""
23
  label_html=""
24
  try:
@@ -69,5 +127,7 @@ with gr.Blocks() as app:
69
  label_output = gr.HTML()
70
 
71
  app.load(find_dataset,None,channel)
72
- channel.change(load_vid,channel,[output,label_output])
 
 
73
  app.launch(show_api=False,share=False)
 
18
  pass
19
  return (gr.Dropdown(label="Channels", choices=[s for s in channels],interactive=True))
20
 
21
+
22
  def load_vid(channel):
23
+ out_html=""
24
+ label_html=""
25
+ vid_list=[]
26
+ sync_list
27
+ try:
28
+ file_box = [info.path for info in list_files_info(f'{channel}', repo_type="dataset")]
29
+ ai_tube_box = [info.path for info in list_files_info(f'{source_dataset}', repo_type="dataset")]
30
+ for file in file_box:
31
+ if file.startswith("prompt_"):
32
+ prompt_slug = file.split("prompt_",1)[1].split(".",1)[0]
33
+ out_html=f'{out_html}<pre> • {file}</pre>'
34
+ #print(prompt_slug)
35
+ for vid_file in ai_tube_box:
36
+ try:
37
+ vid_slug=vid_file.split("videos/",1)[1].split(".",1)[0]
38
+ #print(vid_slug)
39
+ try:
40
+ if vid_slug == prompt_slug:
41
+ out_html=f'{out_html}<pre> + {vid_file}</pre>'
42
+
43
+ if vid_file.endswith(".json"):
44
+ r = requests.get(f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/raw/main/videos/{vid_slug}.json')
45
+ #r = requests.get(f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/blob/main/videos/00b4bcda-7b4a-40f8-9833-e490425a7b91.mp4')
46
+ json_out=r.json()
47
+ label_html=f'{label_html}{json_out["label"]}<br>{json_out["description"]}<br>'
48
+ #print (r.json())
49
+ if vid_file.endswith(".mp4"):
50
+ vid_list.append(json_out["label"])
51
+ sync_list.append(vid_file)
52
+ #<source src="https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/resolve/main/videos/{vid_file}" type="video/mp4">
53
+ print(vid_file)
54
+ label_html=f'''{label_html}
55
+ <video src="https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/resolve/main/{vid_file}" controls>
56
+ </video>'''
57
+ #uid = uuid.uuid4()
58
+ #file = open(f'{name}/{f_name}','wb')
59
+ #file.write(r.content)
60
+ except Exception as e:
61
+ print (f'error:: {e}')
62
+ pass
63
+ except Exception:
64
+ pass
65
+ except Exception as e:
66
+ print(e)
67
+ return(out_html,gr.Dropdown(label="Videos", choices=[s for s in vid_list],interactive=True))
68
+
69
+
70
+ def show_vid(vid_file):
71
+
72
+ #vid_slug=vid_file.split("videos/",1)[1].split(".",1)[0]
73
+
74
+ label_html=f'''{label_html}
75
+ <video src="https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/resolve/main/{vid_file}" controls>
76
+ </video>'''
77
+ return label_html
78
+
79
+ def load_vid_og(channel):
80
  out_html=""
81
  label_html=""
82
  try:
 
127
  label_output = gr.HTML()
128
 
129
  app.load(find_dataset,None,channel)
130
+ channel.change(load_vid,channel,[output,videos])
131
+ videos.change(show_vid,videos,[label_output])
132
+
133
  app.launch(show_api=False,share=False)