Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ def parse_list_boxes(text):
|
|
13 |
matches = re.findall(pattern, text)
|
14 |
return [[float(m) for m in match] for match in matches]
|
15 |
|
16 |
-
def draw_bounding_boxes(image, boxes):
|
17 |
"""Zeichnet Bounding Boxes auf das Bild"""
|
18 |
draw = ImageDraw.Draw(image)
|
19 |
width, height = image.size
|
@@ -25,8 +25,29 @@ def draw_bounding_boxes(image, boxes):
|
|
25 |
xmax * width,
|
26 |
ymax * height
|
27 |
], outline="red", width=3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
return image
|
29 |
|
|
|
30 |
# Streamlit UI
|
31 |
st.title("Bildanalyse mit Gemini")
|
32 |
col1, col2 = st.columns(2)
|
@@ -68,6 +89,7 @@ with col1:
|
|
68 |
model="gemini-2.0-flash-exp",
|
69 |
contents=[detection_prompt, image_part]
|
70 |
)
|
|
|
71 |
|
72 |
# Verarbeitung
|
73 |
boxes = parse_list_boxes(box_response.text)
|
|
|
13 |
matches = re.findall(pattern, text)
|
14 |
return [[float(m) for m in match] for match in matches]
|
15 |
|
16 |
+
'''def draw_bounding_boxes(image, boxes):
|
17 |
"""Zeichnet Bounding Boxes auf das Bild"""
|
18 |
draw = ImageDraw.Draw(image)
|
19 |
width, height = image.size
|
|
|
25 |
xmax * width,
|
26 |
ymax * height
|
27 |
], outline="red", width=3)
|
28 |
+
return image'''
|
29 |
+
|
30 |
+
def draw_bounding_boxes(image, boxes):
|
31 |
+
"""Zeichnet Bounding Boxes auf das Bild"""
|
32 |
+
draw = ImageDraw.Draw(image)
|
33 |
+
width, height = image.size
|
34 |
+
|
35 |
+
for box in boxes:
|
36 |
+
# Sicherstellen, dass alle Werte zwischen 0-1 liegen
|
37 |
+
ymin = max(0.0, min(1.0, box[0]))
|
38 |
+
xmin = max(0.0, min(1.0, box[1]))
|
39 |
+
ymax = max(0.0, min(1.0, box[2]))
|
40 |
+
xmax = max(0.0, min(1.0, box[3]))
|
41 |
+
|
42 |
+
draw.rectangle([
|
43 |
+
xmin * width,
|
44 |
+
ymin * height,
|
45 |
+
xmax * width,
|
46 |
+
ymax * height
|
47 |
+
], outline="red", width=5) # Dickere Linien
|
48 |
return image
|
49 |
|
50 |
+
|
51 |
# Streamlit UI
|
52 |
st.title("Bildanalyse mit Gemini")
|
53 |
col1, col2 = st.columns(2)
|
|
|
89 |
model="gemini-2.0-flash-exp",
|
90 |
contents=[detection_prompt, image_part]
|
91 |
)
|
92 |
+
st.write("Raw API Response:", box_response.text)
|
93 |
|
94 |
# Verarbeitung
|
95 |
boxes = parse_list_boxes(box_response.text)
|