import gradio as gr import requests.exceptions from huggingface_hub import HfApi, hf_hub_download from huggingface_hub.repocard import metadata_load def load_agent(model_id): """ This function load the agent's video and results :return: video_path """ # Load the metrics metadata = get_metadata(model_id) # Get the accuracy results = parse_metrics_accuracy(metadata) # Load the video video_path = hf_hub_download(model_id, filename="replay.mp4") return video_path, results def parse_metrics_accuracy(meta): if "model-index" not in meta: return None result = meta["model-index"][0]["results"] metrics = result[0]["metrics"] accuracy = metrics[0]["value"] return accuracy def get_metadata(model_id): """ Get the metadata of the model repo :param model_id: :return: metadata """ try: readme_path = hf_hub_download(model_id, filename="README.md") metadata = metadata_load(readme_path) print(metadata) return metadata except requests.exceptions.HTTPError: return None agent1 = gr.Interface(load_agent_video, "text", ["video", "text"]) agent2 = gr.Interface(load_agent_video, "text", ["video", "text"]) gr.Parallel(agent1, agent2).launch(share=True)