dustalov commited on
Commit
f4a098d
1 Parent(s): 83143d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -17,8 +17,9 @@
17
  __author__ = 'Dmitry Ustalov'
18
  __license__ = 'Apache 2.0'
19
 
 
20
  from functools import partial
21
- from typing import IO, Tuple, List, cast, Dict, Set, Callable
22
 
23
  import gradio as gr
24
  import networkx as nx
@@ -71,13 +72,13 @@ def bradley_terry(wins: npt.NDArray[np.int_], ties: npt.NDArray[np.int_],
71
  return p
72
 
73
 
74
- def centrality(algorithm: Callable[[nx.DiGraph], Dict[int, float]],
75
  wins: npt.NDArray[np.int_], ties: npt.NDArray[np.int_]) -> npt.NDArray[np.float_]:
76
  A = wins + .5 * ties
77
 
78
  G = nx.from_numpy_array(A, create_using=nx.DiGraph)
79
 
80
- scores: Dict[int, float] = algorithm(G)
81
 
82
  p = np.array([scores[i] for i in range(len(G))])
83
 
@@ -162,15 +163,15 @@ ALGORITHMS = {
162
  }
163
 
164
 
165
- def largest_strongly_connected_component(df: pd.DataFrame) -> Set[str]:
166
  G = nx.from_pandas_edgelist(df, source='left', target='right', create_using=nx.DiGraph)
167
  H = nx.from_pandas_edgelist(df[df['winner'] == 'tie'], source='right', target='left', create_using=nx.DiGraph)
168
  F = nx.compose(G, H)
169
  largest = max(nx.strongly_connected_components(F), key=len)
170
- return cast(Set[str], largest)
171
 
172
 
173
- def handler(file: IO[bytes], algorithm: str, filtered: bool, truncated: bool, seed: int) -> Tuple[pd.DataFrame, Figure]:
174
  if file is None:
175
  raise gr.Error('File must be uploaded')
176
 
@@ -258,7 +259,7 @@ def main() -> None:
258
  label='Comparisons'
259
  ),
260
  gr.Dropdown(
261
- choices=cast(List[str], ALGORITHMS),
262
  value='Bradley-Terry (1952)',
263
  label='Algorithm'
264
  ),
 
17
  __author__ = 'Dmitry Ustalov'
18
  __license__ = 'Apache 2.0'
19
 
20
+ from collections.abc import Callable
21
  from functools import partial
22
+ from typing import BinaryIO, cast
23
 
24
  import gradio as gr
25
  import networkx as nx
 
72
  return p
73
 
74
 
75
+ def centrality(algorithm: Callable[[nx.DiGraph], dict[int, float]],
76
  wins: npt.NDArray[np.int_], ties: npt.NDArray[np.int_]) -> npt.NDArray[np.float_]:
77
  A = wins + .5 * ties
78
 
79
  G = nx.from_numpy_array(A, create_using=nx.DiGraph)
80
 
81
+ scores: dict[int, float] = algorithm(G)
82
 
83
  p = np.array([scores[i] for i in range(len(G))])
84
 
 
163
  }
164
 
165
 
166
+ def largest_strongly_connected_component(df: pd.DataFrame) -> set[str]:
167
  G = nx.from_pandas_edgelist(df, source='left', target='right', create_using=nx.DiGraph)
168
  H = nx.from_pandas_edgelist(df[df['winner'] == 'tie'], source='right', target='left', create_using=nx.DiGraph)
169
  F = nx.compose(G, H)
170
  largest = max(nx.strongly_connected_components(F), key=len)
171
+ return cast(set[str], largest)
172
 
173
 
174
+ def handler(file: BinaryIO, algorithm: str, filtered: bool, truncated: bool, seed: int) -> tuple[pd.DataFrame, Figure]:
175
  if file is None:
176
  raise gr.Error('File must be uploaded')
177
 
 
259
  label='Comparisons'
260
  ),
261
  gr.Dropdown(
262
+ choices=cast(list[str], ALGORITHMS),
263
  value='Bradley-Terry (1952)',
264
  label='Algorithm'
265
  ),