import gradio as gr
from huggingface_hub import HfApi, list_files_info, get_full_repo_name
import requests
import json
import os
from PIL import Image
import urllib.request
import uuid
uid=uuid.uuid4()
token = ""
source_dataset = "jbilcke-hf/ai-tube-index"
api = HfApi(token=token)
token_self = os.environ['HF_TOKEN']
def find_dataset(author=""):
s_ist = (api.list_datasets(author=author,search="ai-tube"))
#print(api.whoami())
channels=[]
videos=[]
for space in s_ist:
try:
channels.append(space.id)
except Exception:
pass
return (gr.Dropdown(label="Channels", choices=[s for s in channels],interactive=True))
def load_vid(channel):
out_html=""
label_html=""
vid_list=[]
sync_list=[]
try:
file_box = [info.path for info in list_files_info(f'{channel}', 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_slug == prompt_slug:
out_html=f'{out_html}
Your Interactive Twitter Card Embed Link is: {t_link}
Your Interactive Mastodon Card Embed Link is: {t_link3}
Your Interactive Gab Card Embed Link is: {t_link2}
''')
except Exception as e:
return gr.HTML(f"""{str(e)}""")
#########################################
with gr.Blocks() as app:
with gr.Row():
channel = gr.Dropdown()
videos = gr.Dropdown()
button = gr.Button()
output = gr.HTML()
label_output = gr.HTML()
links_output = gr.HTML()
list_hid=gr.JSON(visible=False)
app.load(find_dataset,None,channel)
channel.change(load_vid,channel,[output,videos,list_hid])
videos.change(show_vid,[videos,list_hid],[label_output])
button.click(build_space,[videos,list_hid],links_output)
app.launch(show_api=False,share=False)