Commit ·
a1e3dd3
1
Parent(s): 4c5ece4
hotfix: Ajuste na tipagem
Browse files- .gitignore +2 -1
- src/__pycache__/main.cpython-38.pyc +0 -0
- src/main.py +10 -8
- src/models/__pycache__/VLM.cpython-38.pyc +0 -0
- src/models/__pycache__/__init__.cpython-38.pyc +0 -0
- src/models/__pycache__/cam.cpython-38.pyc +0 -0
- src/models/__pycache__/gatedResidualBlock.cpython-38.pyc +0 -0
- src/models/__pycache__/inference.cpython-38.pyc +0 -0
- src/models/__pycache__/loadImageModelClassifier.cpython-38.pyc +0 -0
- src/models/__pycache__/metablock.cpython-38.pyc +0 -0
- src/models/__pycache__/metadata_builder.cpython-38.pyc +0 -0
- src/models/__pycache__/metadata_groups.cpython-38.pyc +0 -0
- src/models/__pycache__/metadata_schema.cpython-38.pyc +0 -0
- src/models/__pycache__/metanet.cpython-38.pyc +0 -0
- src/models/__pycache__/model_loader.cpython-38.pyc +0 -0
- src/models/__pycache__/multimodalIntraInterModal.cpython-38.pyc +0 -0
- src/models/__pycache__/multimodalMDNet.cpython-38.pyc +0 -0
- src/models/__pycache__/preprocessing.cpython-38.pyc +0 -0
- src/models/__pycache__/tab_transformer.cpython-38.pyc +0 -0
.gitignore
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
*.pickle
|
| 2 |
-
*.pyc
|
|
|
|
|
|
| 1 |
*.pickle
|
| 2 |
+
*.pyc
|
| 3 |
+
src/__pycache__/*.pyc
|
src/__pycache__/main.cpython-38.pyc
DELETED
|
Binary file (6.17 kB)
|
|
|
src/main.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from models.inference import (
|
| 3 |
run_inference,
|
| 4 |
get_available_model_choices,
|
|
@@ -34,35 +36,35 @@ custom_css = """
|
|
| 34 |
# ==========================================================
|
| 35 |
# HELPERS (Nomes de variáveis e lógica preservados)
|
| 36 |
# ==========================================================
|
| 37 |
-
def format_groups(enabled_groups):
|
| 38 |
if not enabled_groups: return "No metadata group selected."
|
| 39 |
label_map = dict(GROUP_CHOICES)
|
| 40 |
return " | ".join([label_map.get(g, g) for g in enabled_groups])
|
| 41 |
|
| 42 |
-
def safe_bool(value):
|
| 43 |
return bool(value)
|
| 44 |
|
| 45 |
-
def build_values_dict(age, gender, region, diameter1, diameter2, itch, grew, hurt, changed, bleed, elevation):
|
| 46 |
return dict(
|
| 47 |
age=age, gender=gender, region=region, diameter_1=diameter1, diameter_2=diameter2,
|
| 48 |
itch=safe_bool(itch), grew=safe_bool(grew), hurt=safe_bool(hurt),
|
| 49 |
changed=safe_bool(changed), bleed=safe_bool(bleed), elevation=safe_bool(elevation),
|
| 50 |
)
|
| 51 |
|
| 52 |
-
def build_metadata_preview(enabled_groups, age, gender, region, diameter1, diameter2, itch, grew, hurt, changed, bleed, elevation):
|
| 53 |
values = build_values_dict(age, gender, region, diameter1, diameter2, itch, grew, hurt, changed, bleed, elevation)
|
| 54 |
metadata_csv = build_metadata_csv(values, enabled_groups)
|
| 55 |
groups_text = format_groups(enabled_groups)
|
| 56 |
return metadata_csv, groups_text
|
| 57 |
|
| 58 |
-
def validate_inputs(image, enabled_groups, age, diameter1, diameter2):
|
| 59 |
if image is None: raise gr.Error("Please upload a dermoscopic image first.")
|
| 60 |
if not enabled_groups: raise gr.Error("Please select at least one metadata group.")
|
| 61 |
if age is None or age < 0: raise gr.Error("Age must be a valid non-negative number.")
|
| 62 |
if diameter1 is None or diameter1 < 0: raise gr.Error("Diameter 1 must be a valid non-negative number.")
|
| 63 |
if diameter2 is None or diameter2 < 0: raise gr.Error("Diameter 2 must be a valid non-negative number.")
|
| 64 |
|
| 65 |
-
def gradio_predict(image, selected_model_key, enabled_groups, age, gender, region, diameter1, diameter2, itch, grew, hurt, changed, bleed, elevation):
|
| 66 |
validate_inputs(image, enabled_groups, age, diameter1, diameter2)
|
| 67 |
values = build_values_dict(age, gender, region, diameter1, diameter2, itch, grew, hurt, changed, bleed, elevation)
|
| 68 |
metadata_csv = build_metadata_csv(values, enabled_groups)
|
|
@@ -82,13 +84,13 @@ def gradio_predict(image, selected_model_key, enabled_groups, age, gender, regio
|
|
| 82 |
)
|
| 83 |
return image, heatmap_img, pretty_prediction, metadata_csv, groups_text
|
| 84 |
|
| 85 |
-
def clear_all():
|
| 86 |
default_model = DEFAULT_MODEL_KEY
|
| 87 |
if default_model is None and MODEL_CHOICES:
|
| 88 |
default_model = MODEL_CHOICES[0][1]
|
| 89 |
|
| 90 |
return (
|
| 91 |
-
None, DEFAULT_GROUPS, default_model, 55, "FEMALE", "NECK", 6, 5,
|
| 92 |
False, False, False, False, False, False,
|
| 93 |
None, None, "### Prediction Result\n\nRun the model to see the output here.",
|
| 94 |
"", format_groups(DEFAULT_GROUPS)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from typing import Tuple, List, Optional, Any
|
| 3 |
+
from PIL.Image import Image as PILImage
|
| 4 |
from models.inference import (
|
| 5 |
run_inference,
|
| 6 |
get_available_model_choices,
|
|
|
|
| 36 |
# ==========================================================
|
| 37 |
# HELPERS (Nomes de variáveis e lógica preservados)
|
| 38 |
# ==========================================================
|
| 39 |
+
def format_groups(enabled_groups: List[str]) -> str:
|
| 40 |
if not enabled_groups: return "No metadata group selected."
|
| 41 |
label_map = dict(GROUP_CHOICES)
|
| 42 |
return " | ".join([label_map.get(g, g) for g in enabled_groups])
|
| 43 |
|
| 44 |
+
def safe_bool(value: Any) -> bool:
|
| 45 |
return bool(value)
|
| 46 |
|
| 47 |
+
def build_values_dict(age: float, gender: str, region: str, diameter1: float, diameter2: float, itch: bool, grew: bool, hurt: bool, changed: bool, bleed: bool, elevation: bool) -> dict:
|
| 48 |
return dict(
|
| 49 |
age=age, gender=gender, region=region, diameter_1=diameter1, diameter_2=diameter2,
|
| 50 |
itch=safe_bool(itch), grew=safe_bool(grew), hurt=safe_bool(hurt),
|
| 51 |
changed=safe_bool(changed), bleed=safe_bool(bleed), elevation=safe_bool(elevation),
|
| 52 |
)
|
| 53 |
|
| 54 |
+
def build_metadata_preview(enabled_groups: List[str], age: float, gender: str, region: str, diameter1: float, diameter2: float, itch: bool, grew: bool, hurt: bool, changed: bool, bleed: bool, elevation: bool) -> Tuple[str, str]:
|
| 55 |
values = build_values_dict(age, gender, region, diameter1, diameter2, itch, grew, hurt, changed, bleed, elevation)
|
| 56 |
metadata_csv = build_metadata_csv(values, enabled_groups)
|
| 57 |
groups_text = format_groups(enabled_groups)
|
| 58 |
return metadata_csv, groups_text
|
| 59 |
|
| 60 |
+
def validate_inputs(image: Optional[PILImage], enabled_groups: List[str], age: Optional[float], diameter1: Optional[float], diameter2: Optional[float]) -> None:
|
| 61 |
if image is None: raise gr.Error("Please upload a dermoscopic image first.")
|
| 62 |
if not enabled_groups: raise gr.Error("Please select at least one metadata group.")
|
| 63 |
if age is None or age < 0: raise gr.Error("Age must be a valid non-negative number.")
|
| 64 |
if diameter1 is None or diameter1 < 0: raise gr.Error("Diameter 1 must be a valid non-negative number.")
|
| 65 |
if diameter2 is None or diameter2 < 0: raise gr.Error("Diameter 2 must be a valid non-negative number.")
|
| 66 |
|
| 67 |
+
def gradio_predict(image: PILImage, selected_model_key: str, enabled_groups: List[str], age: float, gender: str, region: str, diameter1: float, diameter2: float, itch: bool, grew: bool, hurt: bool, changed: bool, bleed: bool, elevation: bool) -> Tuple[PILImage, PILImage, str, str, str]:
|
| 68 |
validate_inputs(image, enabled_groups, age, diameter1, diameter2)
|
| 69 |
values = build_values_dict(age, gender, region, diameter1, diameter2, itch, grew, hurt, changed, bleed, elevation)
|
| 70 |
metadata_csv = build_metadata_csv(values, enabled_groups)
|
|
|
|
| 84 |
)
|
| 85 |
return image, heatmap_img, pretty_prediction, metadata_csv, groups_text
|
| 86 |
|
| 87 |
+
def clear_all() -> Tuple[None, List[str], str, float, str, str, float, float, bool, bool, bool, bool, bool, bool, None, None, str, str, str]:
|
| 88 |
default_model = DEFAULT_MODEL_KEY
|
| 89 |
if default_model is None and MODEL_CHOICES:
|
| 90 |
default_model = MODEL_CHOICES[0][1]
|
| 91 |
|
| 92 |
return (
|
| 93 |
+
None, DEFAULT_GROUPS, default_model, 55.0, "FEMALE", "NECK", 6.0, 5.0,
|
| 94 |
False, False, False, False, False, False,
|
| 95 |
None, None, "### Prediction Result\n\nRun the model to see the output here.",
|
| 96 |
"", format_groups(DEFAULT_GROUPS)
|
src/models/__pycache__/VLM.cpython-38.pyc
DELETED
|
Binary file (5.96 kB)
|
|
|
src/models/__pycache__/__init__.cpython-38.pyc
DELETED
|
Binary file (158 Bytes)
|
|
|
src/models/__pycache__/cam.cpython-38.pyc
DELETED
|
Binary file (1.87 kB)
|
|
|
src/models/__pycache__/gatedResidualBlock.cpython-38.pyc
DELETED
|
Binary file (2.17 kB)
|
|
|
src/models/__pycache__/inference.cpython-38.pyc
DELETED
|
Binary file (6.47 kB)
|
|
|
src/models/__pycache__/loadImageModelClassifier.cpython-38.pyc
DELETED
|
Binary file (3.28 kB)
|
|
|
src/models/__pycache__/metablock.cpython-38.pyc
DELETED
|
Binary file (1.08 kB)
|
|
|
src/models/__pycache__/metadata_builder.cpython-38.pyc
DELETED
|
Binary file (1.17 kB)
|
|
|
src/models/__pycache__/metadata_groups.cpython-38.pyc
DELETED
|
Binary file (517 Bytes)
|
|
|
src/models/__pycache__/metadata_schema.cpython-38.pyc
DELETED
|
Binary file (573 Bytes)
|
|
|
src/models/__pycache__/metanet.cpython-38.pyc
DELETED
|
Binary file (3.36 kB)
|
|
|
src/models/__pycache__/model_loader.cpython-38.pyc
DELETED
|
Binary file (2.01 kB)
|
|
|
src/models/__pycache__/multimodalIntraInterModal.cpython-38.pyc
DELETED
|
Binary file (5.98 kB)
|
|
|
src/models/__pycache__/multimodalMDNet.cpython-38.pyc
DELETED
|
Binary file (3.28 kB)
|
|
|
src/models/__pycache__/preprocessing.cpython-38.pyc
DELETED
|
Binary file (2.69 kB)
|
|
|
src/models/__pycache__/tab_transformer.cpython-38.pyc
DELETED
|
Binary file (2.16 kB)
|
|
|