Spaces:
Build error
Build error
Victoria Oberascher
commited on
Commit
·
ce4a7e9
1
Parent(s):
631b1f0
reset app.py
Browse files
app.py
CHANGED
@@ -1,63 +1,9 @@
|
|
1 |
import evaluate
|
2 |
-
import
|
3 |
-
import os
|
4 |
-
import re
|
5 |
-
import sys
|
6 |
-
from pathlib import Path
|
7 |
-
|
8 |
-
module = evaluate.load("SEA-AI/horizon-metrics")
|
9 |
-
|
10 |
-
REGEX_YAML_BLOCK = re.compile(r"---[\n\r]+([\S\s]*?)[\n\r]+---[\n\r]")
|
11 |
-
|
12 |
-
|
13 |
-
def json_to_string_type(input_types):
|
14 |
-
"""Maps json input type to str."""
|
15 |
-
return ["str" if i == "json" else i for i in input_types]
|
16 |
-
|
17 |
-
|
18 |
-
def parse_readme(filepath):
|
19 |
-
"""Parses a repositories README and removes"""
|
20 |
-
if not os.path.exists(filepath):
|
21 |
-
return "No README.md found."
|
22 |
-
with open(filepath, "r") as f:
|
23 |
-
text = f.read()
|
24 |
-
match = REGEX_YAML_BLOCK.search(text)
|
25 |
-
if match:
|
26 |
-
text = text[match.end():]
|
27 |
-
return text
|
28 |
-
|
29 |
-
|
30 |
-
def launch_gradio_widget(metric):
|
31 |
-
"""Launches `metric` widget with Gradio."""
|
32 |
-
|
33 |
-
try:
|
34 |
-
import gradio as gr
|
35 |
-
except ImportError as error:
|
36 |
-
print(
|
37 |
-
"To create a metric widget with Gradio make sure gradio is installed."
|
38 |
-
)
|
39 |
-
raise error
|
40 |
-
|
41 |
-
local_path = Path(sys.path[0])
|
42 |
-
|
43 |
-
def compute(data):
|
44 |
-
print(data)
|
45 |
-
|
46 |
-
metric.add(predictions=data, references=data)
|
47 |
-
return metric.compute(
|
48 |
-
) ##**parse_gradio_data(data, gradio_input_types)
|
49 |
-
|
50 |
-
iface = gr.Interface(
|
51 |
-
description=
|
52 |
-
(metric.info.description +
|
53 |
-
"\nPass the predictions and the groud truth in the format specified below."
|
54 |
-
),
|
55 |
-
title=f"Metric: {metric.name}",
|
56 |
-
article=parse_readme(local_path / "README.md"),
|
57 |
-
# examples=[parse_test_cases(test_cases, feature_names, gradio_input_types)]
|
58 |
-
)
|
59 |
-
|
60 |
-
iface.launch()
|
61 |
-
|
62 |
|
|
|
|
|
|
|
|
|
|
|
63 |
launch_gradio_widget(module)
|
|
|
1 |
import evaluate
|
2 |
+
from evaluate.utils import launch_gradio_widget
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
module = evaluate.load("SEA-AI/horizon-metrics",
|
5 |
+
roll_threshold=0.5,
|
6 |
+
pitch_threshold=0.1,
|
7 |
+
vertical_fov_degrees=25.6,
|
8 |
+
height=512)
|
9 |
launch_gradio_widget(module)
|