Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image, ImageDraw
|
4 |
-
import torch
|
5 |
|
6 |
st.set_page_config(
|
7 |
page_title="Fraktur Detektion",
|
@@ -11,86 +10,31 @@ st.set_page_config(
|
|
11 |
|
12 |
st.markdown("""
|
13 |
<style>
|
14 |
-
/* Reset et base */
|
15 |
.stApp {
|
16 |
-
background-color: var(--background-color) !important;
|
17 |
padding: 0 !important;
|
18 |
-
overflow: hidden !important;
|
19 |
height: 100vh !important;
|
|
|
20 |
}
|
21 |
|
22 |
-
/* Variables de thème */
|
23 |
-
[data-theme="light"] {
|
24 |
-
--background-color: #ffffff;
|
25 |
-
--text-color: #1f2937;
|
26 |
-
--border-color: #e5e7eb;
|
27 |
-
--secondary-bg: #f3f4f6;
|
28 |
-
}
|
29 |
-
|
30 |
-
[data-theme="dark"] {
|
31 |
-
--background-color: #1f2937;
|
32 |
-
--text-color: #f3f4f6;
|
33 |
-
--border-color: #4b5563;
|
34 |
-
--secondary-bg: #374151;
|
35 |
-
}
|
36 |
-
|
37 |
-
/* Layout principal */
|
38 |
.block-container {
|
39 |
-
padding: 0.
|
40 |
max-width: 100% !important;
|
41 |
}
|
42 |
|
43 |
-
/* Contrôles et upload */
|
44 |
-
.uploadedFile {
|
45 |
-
border: 1px dashed var(--border-color);
|
46 |
-
border-radius: 0.375rem;
|
47 |
-
padding: 0.25rem;
|
48 |
-
background: var(--secondary-bg);
|
49 |
-
}
|
50 |
-
|
51 |
-
/* Ajustement des colonnes */
|
52 |
-
[data-testid="column"] {
|
53 |
-
padding: 0 0.5rem !important;
|
54 |
-
}
|
55 |
-
|
56 |
-
/* Images adaptatives */
|
57 |
.stImage > img {
|
58 |
-
width:
|
59 |
height: auto !important;
|
60 |
-
max-height:
|
61 |
object-fit: contain !important;
|
62 |
}
|
63 |
|
64 |
-
/* Résultats */
|
65 |
-
.result-box {
|
66 |
-
padding: 0.375rem;
|
67 |
-
border-radius: 0.375rem;
|
68 |
-
margin: 0.25rem 0;
|
69 |
-
background: var(--secondary-bg);
|
70 |
-
border: 1px solid var(--border-color);
|
71 |
-
color: var(--text-color);
|
72 |
-
}
|
73 |
-
|
74 |
-
/* Titres */
|
75 |
h2, h3 {
|
76 |
-
|
77 |
-
padding: 0.5rem 0 !important;
|
78 |
-
font-size: 1rem !important;
|
79 |
-
color: var(--text-color) !important;
|
80 |
-
}
|
81 |
-
|
82 |
-
/* Nettoyage des éléments inutiles */
|
83 |
-
#MainMenu, footer, header, .viewerBadge_container__1QSob, .stDeployButton {
|
84 |
-
display: none !important;
|
85 |
}
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
}
|
91 |
-
|
92 |
-
.element-container {
|
93 |
-
margin: 0.25rem 0 !important;
|
94 |
}
|
95 |
</style>
|
96 |
""", unsafe_allow_html=True)
|
@@ -165,58 +109,37 @@ def main():
|
|
165 |
result_image = draw_boxes(result_image, filtered_preds)
|
166 |
st.image(result_image, use_container_width=True)
|
167 |
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
</div>
|
198 |
-
""", unsafe_allow_html=True)
|
199 |
-
else:
|
200 |
-
st.info("Kein Bruch erkannt.")
|
201 |
else:
|
202 |
st.info("Bitte laden Sie ein Röntgenbild hoch (JPEG, PNG)")
|
203 |
|
204 |
-
# Script pour la synchronisation du thème
|
205 |
-
st.markdown("""
|
206 |
-
<script>
|
207 |
-
function updateTheme(isDark) {
|
208 |
-
document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
|
209 |
-
}
|
210 |
-
|
211 |
-
window.addEventListener('message', function(e) {
|
212 |
-
if (e.data.type === 'theme-change') {
|
213 |
-
updateTheme(e.data.theme === 'dark');
|
214 |
-
}
|
215 |
-
});
|
216 |
-
|
217 |
-
updateTheme(window.matchMedia('(prefers-color-scheme: dark)').matches);
|
218 |
-
</script>
|
219 |
-
""", unsafe_allow_html=True)
|
220 |
-
|
221 |
if __name__ == "__main__":
|
222 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image, ImageDraw
|
|
|
4 |
|
5 |
st.set_page_config(
|
6 |
page_title="Fraktur Detektion",
|
|
|
10 |
|
11 |
st.markdown("""
|
12 |
<style>
|
|
|
13 |
.stApp {
|
|
|
14 |
padding: 0 !important;
|
|
|
15 |
height: 100vh !important;
|
16 |
+
overflow: hidden !important;
|
17 |
}
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
.block-container {
|
20 |
+
padding: 0.25rem !important;
|
21 |
max-width: 100% !important;
|
22 |
}
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
.stImage > img {
|
25 |
+
width: 80% !important;
|
26 |
height: auto !important;
|
27 |
+
max-height: 200px !important;
|
28 |
object-fit: contain !important;
|
29 |
}
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
h2, h3 {
|
32 |
+
font-size: 0.9rem !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
}
|
34 |
|
35 |
+
.result-box {
|
36 |
+
font-size: 0.8rem !important;
|
37 |
+
margin: 0.2rem 0 !important;
|
|
|
|
|
|
|
|
|
38 |
}
|
39 |
</style>
|
40 |
""", unsafe_allow_html=True)
|
|
|
109 |
result_image = draw_boxes(result_image, filtered_preds)
|
110 |
st.image(result_image, use_container_width=True)
|
111 |
|
112 |
+
# Toujours afficher les résultats des autres modèles
|
113 |
+
st.markdown("#### 🎯 KI-Analyse")
|
114 |
+
col_left, col_right = st.columns(2)
|
115 |
+
|
116 |
+
with col_left:
|
117 |
+
st.markdown("**🛡️ Der KnochenWächter**")
|
118 |
+
predictions = models["KnochenWächter"](image)
|
119 |
+
for pred in predictions:
|
120 |
+
score_color = "#22c55e" if pred['score'] > 0.7 else "#eab308"
|
121 |
+
st.markdown(f"""
|
122 |
+
<div class='result-box'>
|
123 |
+
<span style='color: {score_color}; font-weight: 500;'>
|
124 |
+
{pred['score']:.1%}
|
125 |
+
</span> - {translate_label(pred['label'])}
|
126 |
+
</div>
|
127 |
+
""", unsafe_allow_html=True)
|
128 |
+
|
129 |
+
with col_right:
|
130 |
+
st.markdown("**🎓 Der RöntgenMeister**")
|
131 |
+
predictions = models["RöntgenMeister"](image)
|
132 |
+
for pred in predictions:
|
133 |
+
score_color = "#22c55e" if pred['score'] > 0.7 else "#eab308"
|
134 |
+
st.markdown(f"""
|
135 |
+
<div class='result-box'>
|
136 |
+
<span style='color: {score_color}; font-weight: 500;'>
|
137 |
+
{pred['score']:.1%}
|
138 |
+
</span> - {translate_label(pred['label'])}
|
139 |
+
</div>
|
140 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
141 |
else:
|
142 |
st.info("Bitte laden Sie ein Röntgenbild hoch (JPEG, PNG)")
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
if __name__ == "__main__":
|
145 |
main()
|