dustalov commited on
Commit
cad0b30
·
verified ·
1 Parent(s): 435ca1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -23,7 +23,7 @@ import re
23
  import subprocess
24
  from dataclasses import dataclass
25
  from tempfile import NamedTemporaryFile
26
- from typing import Dict, IO, List, cast, Tuple, Optional, Any
27
 
28
  import gradio as gr
29
  import matplotlib.pyplot as plt
@@ -47,7 +47,7 @@ class Algorithm:
47
  global_params: Optional[str] = None
48
  bin: Optional[str] = None
49
 
50
- def args_clustering(self) -> List[str]:
51
  args = [self.name]
52
 
53
  if self.mode:
@@ -66,7 +66,7 @@ class Algorithm:
66
 
67
  return args
68
 
69
- def args_graph(self) -> List[str]:
70
  args = []
71
 
72
  if self.local_name:
@@ -78,7 +78,7 @@ class Algorithm:
78
  return args
79
 
80
 
81
- ALGORITHMS: Dict[str, Algorithm] = {
82
  'CW_top': Algorithm('cw', 'top'),
83
  'CW_lin': Algorithm('cw', 'lin'),
84
  'CW_log': Algorithm('cw', 'log'),
@@ -122,8 +122,8 @@ def visualize(G: nx.Graph, seed: int = 0) -> Figure:
122
 
123
 
124
  # noinspection PyPep8Naming
125
- def watset(G: nx.Graph, algorithm: str, seed: int = 0,
126
- jar: str = 'watset.jar', timeout: int = 10) -> Tuple[pd.DataFrame, Optional[nx.Graph]]:
127
  with (NamedTemporaryFile() as graph,
128
  NamedTemporaryFile(mode='rb') as clusters,
129
  NamedTemporaryFile(mode='rb') as senses):
@@ -164,7 +164,7 @@ def watset(G: nx.Graph, algorithm: str, seed: int = 0,
164
  return df_clusters, None
165
 
166
 
167
- def handler(file: IO[bytes], algorithm: str, seed: int) -> Tuple[pd.DataFrame, Figure]:
168
  if file is None:
169
  raise gr.Error('File must be uploaded')
170
 
@@ -178,10 +178,10 @@ def handler(file: IO[bytes], algorithm: str, seed: int) -> Tuple[pd.DataFrame, F
178
  except csv.Error:
179
  delimiter = ','
180
 
181
- G: nx.Graph = nx.read_edgelist(file.name, delimiter=delimiter, comments='\n', data=[('weight', float)])
182
 
183
- mapping: Dict[Any, int] = {}
184
- reverse: Dict[int, Any] = {}
185
 
186
  for i, node in enumerate(G):
187
  mapping[node] = i
@@ -217,7 +217,7 @@ def main() -> None:
217
  label='Graph'
218
  ),
219
  gr.Dropdown(
220
- choices=cast(List[str], ALGORITHMS),
221
  value='Watset[MCL, CW_lin]',
222
  label='Algorithm'
223
  ),
 
23
  import subprocess
24
  from dataclasses import dataclass
25
  from tempfile import NamedTemporaryFile
26
+ from typing import cast, BinaryIO, Optional
27
 
28
  import gradio as gr
29
  import matplotlib.pyplot as plt
 
47
  global_params: Optional[str] = None
48
  bin: Optional[str] = None
49
 
50
+ def args_clustering(self) -> list[str]:
51
  args = [self.name]
52
 
53
  if self.mode:
 
66
 
67
  return args
68
 
69
+ def args_graph(self) -> list[str]:
70
  args = []
71
 
72
  if self.local_name:
 
78
  return args
79
 
80
 
81
+ ALGORITHMS: dict[str, Algorithm] = {
82
  'CW_top': Algorithm('cw', 'top'),
83
  'CW_lin': Algorithm('cw', 'lin'),
84
  'CW_log': Algorithm('cw', 'log'),
 
122
 
123
 
124
  # noinspection PyPep8Naming
125
+ def watset(G: nx.Graph[str], algorithm: str, seed: int = 0,
126
+ jar: str = 'watset.jar', timeout: int = 10) -> tuple[pd.DataFrame, Optional[nx.Graph[str]]]:
127
  with (NamedTemporaryFile() as graph,
128
  NamedTemporaryFile(mode='rb') as clusters,
129
  NamedTemporaryFile(mode='rb') as senses):
 
164
  return df_clusters, None
165
 
166
 
167
+ def handler(file: BinaryIO, algorithm: str, seed: int) -> tuple[pd.DataFrame, Figure]:
168
  if file is None:
169
  raise gr.Error('File must be uploaded')
170
 
 
178
  except csv.Error:
179
  delimiter = ','
180
 
181
+ G: nx.Graph[str] = nx.read_edgelist(file.name, delimiter=delimiter, comments='\n', data=[('weight', float)])
182
 
183
+ mapping: dict[str, int] = {}
184
+ reverse: dict[int, str] = {}
185
 
186
  for i, node in enumerate(G):
187
  mapping[node] = i
 
217
  label='Graph'
218
  ),
219
  gr.Dropdown(
220
+ choices=cast(list[str], ALGORITHMS),
221
  value='Watset[MCL, CW_lin]',
222
  label='Algorithm'
223
  ),