import gradio as gr
from huggingface_hub import HfApi, list_files_info
import requests
import json
token = ""
source_dataset = "jbilcke-hf/ai-tube-index"
api = HfApi(token=token)
def find_dataset(author=None):
s_ist = (api.list_datasets(author=author,search="ai-tube"))
#print(api.whoami())
authors=[]
videos=[]
out_html=""
for space in s_ist:
#for i,space in enumerate(s_ist):
try:
space_loc=space.id
space_auth=space_loc.split("/",1)[0]
space_name=space_loc.split("/",1)[0]
#space_ea = space.id.split("/",1)[1]
authors.append(space.id)
except Exception:
pass
return (gr.Dropdown.update(label="Spaces", choices=[s for s in spaces])
def find_dataset_og(author=None):
s_ist = (api.list_datasets(author=author,search="ai-tube"))
#print(api.whoami())
spaces=[]
out_html=""
for space in s_ist:
#for i,space in enumerate(s_ist):
try:
#space_ea = space.id.split("/",1)[1]
spaces.append(f'{space.id}
')
out_html = f'{out_html}{space.id}
'
file_box = [info.path for info in list_files_info(f'{space.id}', repo_type="dataset")]
ai_tube_box = [info.path for info in list_files_info(f'{source_dataset}', repo_type="dataset")]
for file in file_box:
if file.startswith("prompt_"):
prompt_slug = file.split("prompt_",1)[1].split(".",1)[0]
out_html=f'{out_html}
• {file}' print(prompt_slug) for vid_file in ai_tube_box: try: vid_slug=vid_file.split("videos/",1)[1].split(".",1)[0] print(vid_slug) try: if vid_file.endswith(".json"): r = requests.get(f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/raw/main/videos/{vid_slug}.json') #r = requests.get(f'https://huggingface.co/datasets/jbilcke-hf/ai-tube-index/blob/main/videos/00b4bcda-7b4a-40f8-9833-e490425a7b91.mp4') print (r.content) #uid = uuid.uuid4() #file = open(f'{name}/{f_name}','wb') #file.write(r.content) except Exception as e: print (f'error:: {e}') pass try: if vid_slug == prompt_slug: out_html=f'{out_html}
+ {vid_file}' except Exception: pass except Exception: pass #print([info.path for info in list_files_info(f'{space.id}', repo_type="dataset")]) #print(space.id) except Exception as e: print(e) #s_info=api.space_info(f'{name}/{space}',files_metadata=True) #print(s_info) print(spaces) return(out_html) with gr.Blocks() as app: author = gr.Dropdown(label="Author") button = gr.Button() output = gr.HTML() button.click(find_dataset,None,author) app.launch(show_api=False,share=False)