Nathan Fradet commited on
Commit
23160a8
·
unverified ·
1 Parent(s): 9c80799

fixing launch_gradio_widget for new gradio version

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -1,16 +1,35 @@
1
  """Application file."""
2
 
 
 
3
  import evaluate
4
  import gradio as gr
5
 
6
- """module = evaluate.load("Natooz/ece")
 
 
 
 
 
 
 
 
 
 
 
7
  gradio_app = gr.Interface(
8
- module,
9
- inputs=gr.component(),
10
- outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
11
- title=module.name,
12
- )"""
13
- gradio_app = gr.load("Natooz/ece", src="spaces")
 
 
 
 
 
 
14
 
15
 
16
  if __name__ == "__main__":
 
1
  """Application file."""
2
 
3
+ from pathlib import Path
4
+
5
  import evaluate
6
  import gradio as gr
7
 
8
+
9
+ module = evaluate.load("Natooz/ece")
10
+
11
+ # Code taken and adapted from: https://github.com/huggingface/evaluate/blob/main/src/evaluate/utils/gradio.py
12
+ local_path = Path(__file__).parent
13
+ # if there are several input types, use first as default.
14
+ if isinstance(module.features, list):
15
+ (feature_names, feature_types) = zip(*module.features[0].items())
16
+ else:
17
+ (feature_names, feature_types) = zip(*module.features.items())
18
+ gradio_input_types = evaluate.utils.infer_gradio_input_types(feature_types)
19
+
20
  gradio_app = gr.Interface(
21
+ fn=module,
22
+ inputs=gr.Dataframe(
23
+ headers=feature_names,
24
+ col_count=len(feature_names),
25
+ row_count=1,
26
+ datatype=evaluate.utils.json_to_string_type(gradio_input_types),
27
+ ),
28
+ outputs=gr.Textbox(label=module.name),
29
+ description=module.info.description,
30
+ title=f"Metric: {module.name}",
31
+ article=evaluate.utils.parse_readme(local_path / "README.md"),
32
+ )
33
 
34
 
35
  if __name__ == "__main__":