Spaces:
Runtime error
Runtime error
import gradio as gr | |
import requests.exceptions | |
from huggingface_hub import HfApi, hf_hub_download | |
from huggingface_hub.repocard import metadata_load | |
app = gr.Blocks() | |
def load_agent(model_id_1): | |
""" | |
This function load the agent's video and results | |
:return: video_path | |
""" | |
# Load the metrics | |
metadata_1 = get_metadata(model_id_1) | |
# Get the accuracy | |
results_1 = parse_metrics_accuracy(metadata_1) | |
# Load the video | |
video_path_1 = hf_hub_download(model_id_1, filename="replay.mp4") | |
return model_id_1, video_path_1, results_1 | |
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 | |
with app: | |
gr.Markdown( | |
""" | |
# Observa los agentes de Lagomorph en acci贸n 馃 | |
Selecciona el modelo a observar. | |
""") | |
with gr.Row(): | |
model1_input = gr.Textbox(label="Modelo") | |
with gr.Row(): | |
app_button = gr.Button("Mostrar modelo") | |
with gr.Row(): | |
with gr.Column(): | |
model1_name = gr.Markdown() | |
model1_video_output = gr.Video() | |
model1_score_output = gr.Textbox(label="Recompensa +/- Variaci贸n") | |
app_button.click(load_agent, inputs=[model1_input], outputs=[model1_name, model1_video_output, model1_score_output]) | |
examples = gr.Examples(examples=[["odiaz1066/CartPoleGoal-Lagomorph-seed42"], | |
["odiaz1066/BreakoutNoFrameskip-v4-dqn_atari-seed1"], | |
["odiaz1066/PongNoFrameskip-v4-dqn_atari-seed1"]], | |
inputs=[model1_input]) | |
app.launch() |