Skip to content

Commit f394f2a

Browse files
Ruff Check Format
1 parent 8a9ffbd commit f394f2a

29 files changed

+230
-163
lines changed

deploy_hf_space.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from shutil import ignore_patterns
21

32
from huggingface_hub import HfApi
43

@@ -16,10 +15,51 @@
1615
folder_path=".",
1716
repo_id=repo_id,
1817
repo_type="space",
19-
allow_patterns=["data", "docker", "src", ".flaskenv", ".gitattributes", ".gitignore", ".python-version",
20-
"deploy_hf_space.py", "requirements.txt", "README.md", "pyproject.toml", "uv.lock", "dev_boot.sh",
21-
"Dockerfile", "LICENSE", "*.demo", "*.js", "*.css", "*.html", "*.py", "*.sh", "*.json", "*.jpg",
22-
"*.png", "*.pkl", "*.json", "*.npy", "*.txt", "*.md", "*.ini", "*.mako", "README", ".gitkeep"],
23-
ignore_patterns=[".venv", ".github", "dpcs", "flask_session", "joblib_cache", "logs", "notebooks", "tests",
24-
"libcairo.2.dylib", "ontology.json"]
18+
allow_patterns=[
19+
"data",
20+
"docker",
21+
"src",
22+
".flaskenv",
23+
".gitattributes",
24+
".gitignore",
25+
".python-version",
26+
"deploy_hf_space.py",
27+
"requirements.txt",
28+
"README.md",
29+
"pyproject.toml",
30+
"uv.lock",
31+
"dev_boot.sh",
32+
"Dockerfile",
33+
"LICENSE",
34+
"*.demo",
35+
"*.js",
36+
"*.css",
37+
"*.html",
38+
"*.py",
39+
"*.sh",
40+
"*.json",
41+
"*.jpg",
42+
"*.png",
43+
"*.pkl",
44+
"*.json",
45+
"*.npy",
46+
"*.txt",
47+
"*.md",
48+
"*.ini",
49+
"*.mako",
50+
"README",
51+
".gitkeep",
52+
],
53+
ignore_patterns=[
54+
".venv",
55+
".github",
56+
"dpcs",
57+
"flask_session",
58+
"joblib_cache",
59+
"logs",
60+
"notebooks",
61+
"tests",
62+
"libcairo.2.dylib",
63+
"ontology.json",
64+
],
2565
)

notebooks/Vocab_datamining.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"import sys\n",
1111
"\n",
1212
"sys.path.append(\"..\")\n",
13-
"import sqlite3\n",
1413
"\n",
1514
"import numpy as np\n",
1615
"import pandas as pd\n",

notebooks/import_ontology.ipynb

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
"source": [
99
"import json\n",
1010
"import random\n",
11+
"\n",
1112
"from pronto import Ontology, Definition\n",
1213
"\n",
13-
"class ImpatientVocab():\n",
14+
"\n",
15+
"class ImpatientVocab:\n",
1416
" def __init__(self) -> None:\n",
1517
" self.used_colors: list[str] = []\n",
1618
" self.impatient_json: list[dict] = []\n",
@@ -20,11 +22,11 @@
2022
" def load_json(self, path: str) -> list[dict]:\n",
2123
" self.impatient_json = json.load(open(path, \"r\"))\n",
2224
" return self.impatient_json\n",
23-
" \n",
25+
"\n",
2426
" def load_ontology(self, path: str) -> Ontology:\n",
2527
" self.impatient_onto = Ontology(path)\n",
2628
" return self.impatient_onto\n",
27-
" \n",
29+
"\n",
2830
" def json_to_onto(self) -> Ontology:\n",
2931
" self.impatient_onto = Ontology()\n",
3032
" for term in self.impatient_json:\n",
@@ -36,11 +38,13 @@
3638
" if term[\"data\"][\"description\"] != \"\":\n",
3739
" added_term.definition = Definition(term[\"data\"][\"description\"])\n",
3840
" if term[\"parent\"] != \"#\":\n",
39-
" added_term.superclasses().add(self.impatient_onto[term[\"parent\"].replace(\"_\", \":\")])\n",
40-
" \n",
41+
" added_term.superclasses().add(\n",
42+
" self.impatient_onto[term[\"parent\"].replace(\"_\", \":\")]\n",
43+
" )\n",
44+
"\n",
4145
" self.list_of_terms.append(added_term)\n",
4246
" return self.impatient_onto\n",
43-
" \n",
47+
"\n",
4448
" def onto_to_json(self) -> list[dict]:\n",
4549
" self.impatient_json = []\n",
4650
" index = 0\n",
@@ -55,8 +59,12 @@
5559
" \"text\": term.name,\n",
5660
" \"icon\": True,\n",
5761
" \"data\": {\n",
58-
" \"description\": term.definition if term.definition is not None else \"\",\n",
59-
" \"synonymes\": \",\".join([syn.description for syn in term.synonyms]),\n",
62+
" \"description\": term.definition\n",
63+
" if term.definition is not None\n",
64+
" else \"\",\n",
65+
" \"synonymes\": \",\".join(\n",
66+
" [syn.description for syn in term.synonyms]\n",
67+
" ),\n",
6068
" \"phenotype_datamined\": \"\",\n",
6169
" \"gene_datamined\": \"\",\n",
6270
" \"alternative_language\": term.name,\n",
@@ -65,12 +73,14 @@
6573
" \"hex_color\": self._generate_hex_color(),\n",
6674
" \"hpo_datamined\": \"\",\n",
6775
" },\n",
68-
" \"parent\": relationships[0].replace(\"_\", \":\") if relationships != [] else \"#\"\n",
76+
" \"parent\": relationships[0].replace(\"_\", \":\")\n",
77+
" if relationships != []\n",
78+
" else \"#\",\n",
6979
" }\n",
7080
" )\n",
7181
" index += 1\n",
7282
" return self.impatient_json\n",
73-
" \n",
83+
"\n",
7484
" def _generate_hex_color(self):\n",
7585
" while True:\n",
7686
" # Generate a random hex color\n",
@@ -80,7 +90,7 @@
8090
" # Add the color to the list of used colors and return it\n",
8191
" self.used_colors.append(color)\n",
8292
" return color\n",
83-
" \n",
93+
"\n",
8494
" def dump_onto(self, path: str) -> None:\n",
8595
" with open(path, \"wb\") as f:\n",
8696
" self.impatient_onto.dump(f, format=\"obo\")\n",

src/impatient/app/dashapp/callbacks.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
import io
21
import base64
2+
import io
33
import json
44
import os
5-
import dash
65
import pickle # nosec
76
import traceback
8-
9-
from flask import current_app
107
from urllib import parse
11-
from joblib import Memory
12-
13-
import numpy as np
14-
import pandas as pd
158

169
import PIL.Image
17-
from skimage import io as skio
18-
from dash.dependencies import Input, Output, State
19-
from dash import html
20-
from dash import dcc
10+
import dash
2111
import dash_bootstrap_components as dbc
12+
import numpy as np
13+
from dash import html
14+
from dash.dependencies import Input, Output, State
15+
from flask import current_app
16+
from joblib import Memory
17+
from skimage import io as skio
2218

23-
from impatient.app import db
24-
import impatient.app.dashapp.plot_common as plot_common
25-
from impatient.app.models import Image
2619
import impatient.app.dashapp.common_func as common_func
20+
import impatient.app.dashapp.plot_common as plot_common
21+
from impatient.app import db
2722
from impatient.app.dashapp.shapes_to_segmentations import (
2823
compute_segmentations,
2924
blend_image_and_classified_regions_pil,
3025
)
31-
3226
from impatient.app.dashapp.trainable_segmentation import multiscale_basic_features
27+
from impatient.app.models import Image
3328

3429
memory = Memory("./joblib_cache", verbose=1)
3530
compute_features = memory.cache(multiscale_basic_features)
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import os
21
import json
2+
import os
33

44

55
def load_onto():
6-
with open(os.path.join("/home/impatient/data/ontology/", "ontology.json"), "r") as fp:
6+
with open(
7+
os.path.join("/home/impatient/data/ontology/", "ontology.json"), "r"
8+
) as fp:
79
onto_tree = json.load(fp)
810
onto_tree_imgannot = [i for i in onto_tree if i["data"]["image_annotation"] == True]
911
return onto_tree_imgannot

src/impatient/app/dashapp/layout.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import os
2+
3+
import dash_bootstrap_components as dbc
14
from dash import dcc
25
from dash import html
3-
import dash_bootstrap_components as dbc
4-
import os
5-
from impatient.app.dashapp import bp
6-
import impatient.app.dashapp.plot_common as plot_common
6+
77
import impatient.app.dashapp.common_func as common_func
8-
import json
8+
import impatient.app.dashapp.plot_common as plot_common
9+
from impatient.app.dashapp import bp
910

1011
DEFAULT_STROKE_WIDTH = 3 # gives line width of 2^3 = 8
1112

src/impatient/app/dashapp/shape_utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from cairosvg import svg2png
2-
import skimage
3-
import PIL.Image
41
import io
2+
3+
import PIL.Image
54
import numpy as np
5+
import skimage
6+
from cairosvg import svg2png
67

78

89
def shape_to_svg_code(shape, fig=None, width=None, height=None):
@@ -38,9 +39,7 @@ def shape_to_svg_code(shape, fig=None, width=None, height=None):
3839
fill-opacity="0"
3940
/>
4041
</svg>
41-
""".format(
42-
**fmt_dict
43-
)
42+
""".format(**fmt_dict)
4443

4544

4645
def shape_to_png(fig=None, shape=None, width=None, height=None, write_to=None):

src/impatient/app/dashapp/shapes_to_segmentations.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
from time import time
2+
13
import PIL.Image
24
import numpy as np
5+
import plotly.express as px
36
import skimage
4-
import skimage.util
5-
import skimage.io
67
import skimage.color
8+
import skimage.io
9+
import skimage.util
10+
from sklearn.ensemble import RandomForestClassifier
11+
712
import impatient.app.dashapp.shape_utils as shape_utils
813
from impatient.app.dashapp.trainable_segmentation import fit_segmenter
9-
import plotly.express as px
10-
from sklearn.ensemble import RandomForestClassifier
11-
from time import time
1214

1315

1416
def img_to_ubyte_array(img):

src/impatient/app/dashapp/trainable_segmentation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from itertools import combinations_with_replacement
21
import itertools
2+
from itertools import combinations_with_replacement
3+
34
import numpy as np
5+
from joblib import Parallel, delayed
46
from skimage import filters, feature
57
from skimage import img_as_float32
6-
from joblib import Parallel, delayed
78

89
try:
910
from sklearn.exceptions import NotFittedError
@@ -12,7 +13,6 @@
1213
except ImportError:
1314
has_sklearn = False
1415

15-
1616
class NotFittedError(Exception):
1717
pass
1818

src/impatient/app/dashapp/use_ml_image_segmentation_classifier.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@
1313
1414
"""
1515

16+
import base64
17+
import io
18+
import json
1619
import os
20+
import pickle # nosec
21+
22+
import skimage.io
23+
1724
import impatient.app.dashapp.plot_common as plot_common
1825
import impatient.app.dashapp.shapes_to_segmentations as shapes_to_segmentations
1926
from impatient.app.dashapp.trainable_segmentation import (
2027
multiscale_basic_features,
2128
predict_segmenter,
2229
)
23-
import pickle # nosec
24-
import base64
25-
import io
26-
import skimage.io
27-
import json
2830

2931

3032
def getenv(e):

src/impatient/app/historeport/forms.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import json
2-
import os
32

4-
import impatient.app.src.common as Common
53
from flask_wtf import FlaskForm
64
from flask_wtf.file import FileAllowed, FileField, FileRequired
75
from wtforms import SelectField, StringField, SubmitField, TextAreaField, fields

src/impatient/app/historeport/ocr.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import collections
21
import json
32
import os
4-
from shlex import join
53

64
import cv2
75
import numpy as np
86
import pytesseract
97
import spacy
108
from flask import current_app
119
from pdf2image import convert_from_bytes
12-
from thefuzz import fuzz
1310
from textacy.extract.basics import ngrams
11+
from thefuzz import fuzz
1412

1513

1614
class TextReport:

src/impatient/app/historeport/onto_func.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import io
12
import json
23
import random
3-
from pronto import Ontology, Definition
4-
import io
4+
55
from flask_wtf.file import FileField
6+
from pronto import Ontology, Definition
67

78

89
class ImpatientVocab:
@@ -35,9 +36,7 @@ def load_ontology_f(self, file: FileField) -> Ontology:
3536

3637
def json_to_onto(self) -> Ontology:
3738
self.impatient_onto = Ontology()
38-
term_mapping = (
39-
{}
40-
) # A dictionary to store term IDs and their corresponding created terms
39+
term_mapping = {} # A dictionary to store term IDs and their corresponding created terms
4140

4241
# First pass: Create terms without adding superclasses
4342
for term in self.impatient_json:

0 commit comments

Comments
 (0)