Spaces:
Build error
Build error
Merge pull request #16 from buuck/show_metric
Browse files- app.py +17 -1
- utils/indicators.py +6 -0
app.py
CHANGED
@@ -12,6 +12,12 @@ metric_names = os.listdir('metrics')
|
|
12 |
for i in range(len(metric_names)):
|
13 |
metric_names[i] = metric_names[i].split('.yaml')[0].replace('_', ' ')
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
with gr.Blocks() as demo:
|
16 |
with gr.Column():
|
17 |
m1 = gr.Plot()
|
@@ -22,7 +28,11 @@ with gr.Blocks() as demo:
|
|
22 |
end_year = gr.Number(value=2022, label="End Year", precision=0)
|
23 |
with gr.Row():
|
24 |
view_btn = gr.Button(value="Show project map")
|
25 |
-
calc_btn = gr.Button(value="Calculate
|
|
|
|
|
|
|
|
|
26 |
results_df = gr.Dataframe(
|
27 |
headers=["Year", "Project Name", "Score"],
|
28 |
datatype=["number", "str", "number"],
|
@@ -57,6 +67,12 @@ with gr.Blocks() as demo:
|
|
57 |
indexgenerator.set_metric,
|
58 |
inputs=metric
|
59 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
# Get url params
|
62 |
url_params = gr.JSON({"username": "default"}, visible=False, label="URL Params")
|
|
|
12 |
for i in range(len(metric_names)):
|
13 |
metric_names[i] = metric_names[i].split('.yaml')[0].replace('_', ' ')
|
14 |
|
15 |
+
def toggle_metric_definition_box(text_input):
|
16 |
+
if text_input is None or text_input == '':
|
17 |
+
return indexgenerator.get_metric_file()
|
18 |
+
else:
|
19 |
+
return None
|
20 |
+
|
21 |
with gr.Blocks() as demo:
|
22 |
with gr.Column():
|
23 |
m1 = gr.Plot()
|
|
|
28 |
end_year = gr.Number(value=2022, label="End Year", precision=0)
|
29 |
with gr.Row():
|
30 |
view_btn = gr.Button(value="Show project map")
|
31 |
+
calc_btn = gr.Button(value="Calculate metric")
|
32 |
+
metric_btn = gr.Button(value='Show/hide metric definition')
|
33 |
+
metric_docs = gr.Textbox(
|
34 |
+
label="The chosen metric is a linear combination of these components normalized to a range of 0 to 1 and with the given coefficients",
|
35 |
+
interactive=False)
|
36 |
results_df = gr.Dataframe(
|
37 |
headers=["Year", "Project Name", "Score"],
|
38 |
datatype=["number", "str", "number"],
|
|
|
67 |
indexgenerator.set_metric,
|
68 |
inputs=metric
|
69 |
)
|
70 |
+
# Toggle display of metric information
|
71 |
+
metric_btn.click(
|
72 |
+
toggle_metric_definition_box,
|
73 |
+
inputs=metric_docs,
|
74 |
+
outputs=metric_docs
|
75 |
+
)
|
76 |
|
77 |
# Get url params
|
78 |
url_params = gr.JSON({"username": "default"}, visible=False, label="URL Params")
|
utils/indicators.py
CHANGED
@@ -339,3 +339,9 @@ class IndexGenerator:
|
|
339 |
if pd.api.types.is_numeric_dtype(x)
|
340 |
else x)
|
341 |
return scores
|
|
|
|
|
|
|
|
|
|
|
|
|
|
339 |
if pd.api.types.is_numeric_dtype(x)
|
340 |
else x)
|
341 |
return scores
|
342 |
+
|
343 |
+
def get_metric_file(self):
|
344 |
+
# Use defined subset of indices
|
345 |
+
indices_file = f'metrics/{self.metric_name.replace(" ", "_")}.yaml'
|
346 |
+
with open(indices_file, "r") as stream:
|
347 |
+
return stream.read()
|