Toy
Claude
commited on
Commit
Β·
e8460b8
1
Parent(s):
5aeda0b
Fix Python 3.9 compatibility - replace union syntax | with Union
Browse files- Replace all `Type | None` syntax with `Union[Type, None]`
- Add typing.Union imports where needed
- Ensures compatibility with Python 3.9.13 on HuggingFace Spaces
π€ Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
- .python-version +1 -1
- src/services/models/flower_classification.py +3 -3
- src/services/models/image_generation.py +3 -1
- src/services/training/dataset.py +2 -1
- src/ui/french_style/french_style_tab.py +3 -2
- src/ui/generate/generate_tab.py +2 -1
- src/ui/identify/identify_tab.py +3 -3
- src/utils/color_utils.py +2 -1
.python-version
CHANGED
@@ -1 +1 @@
|
|
1 |
-
3.
|
|
|
1 |
+
3.12.11
|
src/services/models/flower_classification.py
CHANGED
@@ -3,7 +3,7 @@ Flower classification service using ConvNeXt and CLIP models.
|
|
3 |
"""
|
4 |
|
5 |
import os
|
6 |
-
from typing import Any
|
7 |
|
8 |
import torch
|
9 |
from PIL import Image
|
@@ -88,8 +88,8 @@ class FlowerClassificationService:
|
|
88 |
|
89 |
def identify_flowers(
|
90 |
self,
|
91 |
-
image: Image.Image
|
92 |
-
candidate_labels: list[str]
|
93 |
top_k: int = 7,
|
94 |
min_score: float = 0.12,
|
95 |
) -> tuple[list[list[Any]], str]:
|
|
|
3 |
"""
|
4 |
|
5 |
import os
|
6 |
+
from typing import Any, Union
|
7 |
|
8 |
import torch
|
9 |
from PIL import Image
|
|
|
88 |
|
89 |
def identify_flowers(
|
90 |
self,
|
91 |
+
image: Union[Image.Image, None],
|
92 |
+
candidate_labels: Union[list[str], None] = None,
|
93 |
top_k: int = 7,
|
94 |
min_score: float = 0.12,
|
95 |
) -> tuple[list[list[Any]], str]:
|
src/services/models/image_generation.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
"""Image generation service using SDXL models."""
|
2 |
|
|
|
|
|
3 |
import numpy as np
|
4 |
import torch
|
5 |
from diffusers import AutoPipelineForText2Image
|
@@ -89,7 +91,7 @@ class ImageGenerationService:
|
|
89 |
steps: int = 4,
|
90 |
width: int = 1024,
|
91 |
height: int = 1024,
|
92 |
-
seed: int
|
93 |
) -> Image.Image:
|
94 |
"""Generate an image from a text prompt."""
|
95 |
if seed is None or seed < 0:
|
|
|
1 |
"""Image generation service using SDXL models."""
|
2 |
|
3 |
+
from typing import Union
|
4 |
+
|
5 |
import numpy as np
|
6 |
import torch
|
7 |
from diffusers import AutoPipelineForText2Image
|
|
|
91 |
steps: int = 4,
|
92 |
width: int = 1024,
|
93 |
height: int = 1024,
|
94 |
+
seed: Union[int, None] = None,
|
95 |
) -> Image.Image:
|
96 |
"""Generate an image from a text prompt."""
|
97 |
if seed is None or seed < 0:
|
src/services/training/dataset.py
CHANGED
@@ -3,6 +3,7 @@ Dataset class for flower training data.
|
|
3 |
"""
|
4 |
|
5 |
import os
|
|
|
6 |
|
7 |
import torch
|
8 |
from PIL import Image
|
@@ -15,7 +16,7 @@ class FlowerDataset(Dataset):
|
|
15 |
"""Dataset for flower classification training."""
|
16 |
|
17 |
def __init__(
|
18 |
-
self, image_dir: str, processor, flower_labels: list[str]
|
19 |
):
|
20 |
self.image_paths = []
|
21 |
self.labels = []
|
|
|
3 |
"""
|
4 |
|
5 |
import os
|
6 |
+
from typing import Union
|
7 |
|
8 |
import torch
|
9 |
from PIL import Image
|
|
|
16 |
"""Dataset for flower classification training."""
|
17 |
|
18 |
def __init__(
|
19 |
+
self, image_dir: str, processor, flower_labels: Union[list[str], None] = None
|
20 |
):
|
21 |
self.image_paths = []
|
22 |
self.labels = []
|
src/ui/french_style/french_style_tab.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
"""
|
2 |
French Style tab UI components and logic.
|
3 |
"""
|
|
|
4 |
|
5 |
import gradio as gr
|
6 |
from PIL import Image
|
@@ -68,8 +69,8 @@ class FrenchStyleTab:
|
|
68 |
return "π Processing... Please wait while we analyze your flower image...", ""
|
69 |
|
70 |
def analyze_and_generate(
|
71 |
-
self, image: Image.Image
|
72 |
-
) -> tuple[Image.Image
|
73 |
"""Analyze uploaded flower image and generate French-style arrangement."""
|
74 |
if image is None:
|
75 |
return None, "Please upload an image", ""
|
|
|
1 |
"""
|
2 |
French Style tab UI components and logic.
|
3 |
"""
|
4 |
+
from typing import Union
|
5 |
|
6 |
import gradio as gr
|
7 |
from PIL import Image
|
|
|
69 |
return "π Processing... Please wait while we analyze your flower image...", ""
|
70 |
|
71 |
def analyze_and_generate(
|
72 |
+
self, image: Union[Image.Image, None]
|
73 |
+
) -> tuple[Union[Image.Image, None], str, str]:
|
74 |
"""Analyze uploaded flower image and generate French-style arrangement."""
|
75 |
if image is None:
|
76 |
return None, "Please upload an image", ""
|
src/ui/generate/generate_tab.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
"""
|
2 |
Generate tab UI components and logic.
|
3 |
"""
|
|
|
4 |
|
5 |
import gradio as gr
|
6 |
from PIL import Image
|
@@ -65,7 +66,7 @@ class GenerateTab:
|
|
65 |
|
66 |
def generate_image(
|
67 |
self, prompt: str, steps: int, width: int, height: int, seed: int
|
68 |
-
) -> Image.Image
|
69 |
"""Generate an image from the given parameters."""
|
70 |
try:
|
71 |
return image_generator.generate( # type: ignore
|
|
|
1 |
"""
|
2 |
Generate tab UI components and logic.
|
3 |
"""
|
4 |
+
from typing import Union
|
5 |
|
6 |
import gradio as gr
|
7 |
from PIL import Image
|
|
|
66 |
|
67 |
def generate_image(
|
68 |
self, prompt: str, steps: int, width: int, height: int, seed: int
|
69 |
+
) -> Union[Image.Image, None]:
|
70 |
"""Generate an image from the given parameters."""
|
71 |
try:
|
72 |
return image_generator.generate( # type: ignore
|
src/ui/identify/identify_tab.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
Identify tab UI components and logic.
|
3 |
"""
|
4 |
|
5 |
-
from typing import Any
|
6 |
|
7 |
import gradio as gr
|
8 |
from PIL import Image
|
@@ -84,7 +84,7 @@ class IdentifyTab:
|
|
84 |
|
85 |
def identify_flowers(
|
86 |
self,
|
87 |
-
image: Image.Image
|
88 |
candidate_labels: list[str],
|
89 |
top_k: int,
|
90 |
min_score: float,
|
@@ -97,6 +97,6 @@ class IdentifyTab:
|
|
97 |
min_score=min_score,
|
98 |
)
|
99 |
|
100 |
-
def set_image(self, image: Image.Image
|
101 |
"""Set the image for identification (used by other tabs)."""
|
102 |
return image
|
|
|
2 |
Identify tab UI components and logic.
|
3 |
"""
|
4 |
|
5 |
+
from typing import Any, Union
|
6 |
|
7 |
import gradio as gr
|
8 |
from PIL import Image
|
|
|
84 |
|
85 |
def identify_flowers(
|
86 |
self,
|
87 |
+
image: Union[Image.Image, None],
|
88 |
candidate_labels: list[str],
|
89 |
top_k: int,
|
90 |
min_score: float,
|
|
|
97 |
min_score=min_score,
|
98 |
)
|
99 |
|
100 |
+
def set_image(self, image: Union[Image.Image, None]) -> Union[Image.Image, None]:
|
101 |
"""Set the image for identification (used by other tabs)."""
|
102 |
return image
|
src/utils/color_utils.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
"""
|
2 |
Color analysis utilities.
|
3 |
"""
|
|
|
4 |
|
5 |
import numpy as np
|
6 |
from PIL import Image
|
@@ -8,7 +9,7 @@ from sklearn.cluster import KMeans
|
|
8 |
|
9 |
|
10 |
def extract_dominant_colors(
|
11 |
-
image: Image.Image
|
12 |
) -> tuple[list[str], np.ndarray]:
|
13 |
"""Extract dominant colors from an image using k-means clustering."""
|
14 |
if image is None:
|
|
|
1 |
"""
|
2 |
Color analysis utilities.
|
3 |
"""
|
4 |
+
from typing import Union
|
5 |
|
6 |
import numpy as np
|
7 |
from PIL import Image
|
|
|
9 |
|
10 |
|
11 |
def extract_dominant_colors(
|
12 |
+
image: Union[Image.Image, None], num_colors: int = 5
|
13 |
) -> tuple[list[str], np.ndarray]:
|
14 |
"""Extract dominant colors from an image using k-means clustering."""
|
15 |
if image is None:
|