ThomasSimonini HF staff commited on
Commit
941c44c
1 Parent(s): 844c3ac

Add metrics

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -3,13 +3,31 @@ import requests.exceptions
3
  from huggingface_hub import HfApi, hf_hub_download
4
  from huggingface_hub.repocard import metadata_load
5
 
6
- def load_agent_video(model_id):
7
  """
8
  This function load the agent's video and results
9
  :return: video_path
10
  """
 
 
 
 
 
 
 
11
  video_path = hf_hub_download(model_id, filename="replay.mp4")
12
- return video_path
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  def get_metadata(model_id):
15
  """
@@ -25,8 +43,8 @@ def get_metadata(model_id):
25
  except requests.exceptions.HTTPError:
26
  return None
27
 
28
- agent1 = gr.Interface(load_agent_video, "text", "video")
29
- agent2 = gr.Interface(load_agent_video, "text", "video")
30
 
31
  gr.Parallel(agent1, agent2).launch(share=True)
32
 
3
  from huggingface_hub import HfApi, hf_hub_download
4
  from huggingface_hub.repocard import metadata_load
5
 
6
+ def load_agent(model_id):
7
  """
8
  This function load the agent's video and results
9
  :return: video_path
10
  """
11
+ # Load the metrics
12
+ metadata = get_metadata(model_id)
13
+
14
+ # Get the accuracy
15
+ results = parse_metrics_accuracy(metadata)
16
+
17
+ # Load the video
18
  video_path = hf_hub_download(model_id, filename="replay.mp4")
19
+
20
+ return video_path, results
21
+
22
+
23
+
24
+ def parse_metrics_accuracy(meta):
25
+ if "model-index" not in meta:
26
+ return None
27
+ result = meta["model-index"][0]["results"]
28
+ metrics = result[0]["metrics"]
29
+ accuracy = metrics[0]["value"]
30
+ return accuracy
31
 
32
  def get_metadata(model_id):
33
  """
43
  except requests.exceptions.HTTPError:
44
  return None
45
 
46
+ agent1 = gr.Interface(load_agent_video, "text", ["video", "text"])
47
+ agent2 = gr.Interface(load_agent_video, "text", ["video", "text"])
48
 
49
  gr.Parallel(agent1, agent2).launch(share=True)
50