Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ st.set_page_config(
|
|
9 |
initial_sidebar_state="collapsed"
|
10 |
)
|
11 |
|
|
|
12 |
st.markdown("""
|
13 |
<style>
|
14 |
.stApp {
|
@@ -33,13 +34,15 @@ st.markdown("""
|
|
33 |
}
|
34 |
|
35 |
.stButton > button {
|
|
|
36 |
background-color: var(--button-color) !important;
|
37 |
color: white !important;
|
38 |
border: none !important;
|
39 |
-
padding: 0.5rem
|
40 |
border-radius: 0.375rem !important;
|
41 |
font-weight: 500 !important;
|
42 |
-
|
|
|
43 |
}
|
44 |
|
45 |
.stButton > button:hover {
|
@@ -82,14 +85,14 @@ st.markdown("""
|
|
82 |
padding: 0.25rem;
|
83 |
}
|
84 |
|
85 |
-
.row-widget.stButton {
|
86 |
-
text-align: center;
|
87 |
-
margin: 1rem 0;
|
88 |
-
}
|
89 |
-
|
90 |
div[data-testid="stFileUploader"] {
|
91 |
width: 100%;
|
92 |
}
|
|
|
|
|
|
|
|
|
|
|
93 |
</style>
|
94 |
""", unsafe_allow_html=True)
|
95 |
|
@@ -125,57 +128,62 @@ def draw_boxes(image, predictions):
|
|
125 |
return image
|
126 |
|
127 |
def main():
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
st.
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
if pred_wachter['score'] > 0.6 or pred_meister['score'] > 0.6:
|
164 |
-
st.markdown(f"""
|
165 |
-
<div class='result-box'>
|
166 |
-
<span style='color: #2563eb'>KnochenWächter:</span> {pred_wachter['score']:.1%}<br>
|
167 |
-
<span style='color: #2563eb'>RöntgenMeister:</span> {pred_meister['score']:.1%}
|
168 |
-
</div>
|
169 |
-
""", unsafe_allow_html=True)
|
170 |
|
171 |
-
|
172 |
st.markdown("""
|
173 |
<script>
|
174 |
-
// Fonction pour mettre à jour le thème
|
175 |
function updateTheme(isDark) {
|
176 |
document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
|
177 |
-
|
178 |
-
// Mise à jour des styles en fonction du thème
|
179 |
const root = document.documentElement;
|
180 |
if (isDark) {
|
181 |
root.style.setProperty('--background-color', '#1f2937');
|
@@ -188,14 +196,12 @@ def main():
|
|
188 |
}
|
189 |
}
|
190 |
|
191 |
-
// Écouter les messages du parent
|
192 |
window.addEventListener('message', function(e) {
|
193 |
if (e.data.type === 'theme-change') {
|
194 |
updateTheme(e.data.theme === 'dark');
|
195 |
}
|
196 |
});
|
197 |
|
198 |
-
// Thème initial basé sur les préférences système
|
199 |
updateTheme(window.matchMedia('(prefers-color-scheme: dark)').matches);
|
200 |
</script>
|
201 |
""", unsafe_allow_html=True)
|
|
|
9 |
initial_sidebar_state="collapsed"
|
10 |
)
|
11 |
|
12 |
+
# Configuration du style personnalisé
|
13 |
st.markdown("""
|
14 |
<style>
|
15 |
.stApp {
|
|
|
34 |
}
|
35 |
|
36 |
.stButton > button {
|
37 |
+
width: 100% !important;
|
38 |
background-color: var(--button-color) !important;
|
39 |
color: white !important;
|
40 |
border: none !important;
|
41 |
+
padding: 0.75rem 1.5rem !important;
|
42 |
border-radius: 0.375rem !important;
|
43 |
font-weight: 500 !important;
|
44 |
+
margin: 1rem 0 !important;
|
45 |
+
cursor: pointer !important;
|
46 |
}
|
47 |
|
48 |
.stButton > button:hover {
|
|
|
85 |
padding: 0.25rem;
|
86 |
}
|
87 |
|
|
|
|
|
|
|
|
|
|
|
88 |
div[data-testid="stFileUploader"] {
|
89 |
width: 100%;
|
90 |
}
|
91 |
+
|
92 |
+
/* Cache le message d'upload par défaut */
|
93 |
+
.uploadedFile small {
|
94 |
+
display: none !important;
|
95 |
+
}
|
96 |
</style>
|
97 |
""", unsafe_allow_html=True)
|
98 |
|
|
|
128 |
return image
|
129 |
|
130 |
def main():
|
131 |
+
# Initialisation de la session state si nécessaire
|
132 |
+
if 'models_loaded' not in st.session_state:
|
133 |
+
st.session_state.models_loaded = False
|
134 |
+
st.session_state.models = load_models()
|
135 |
+
st.session_state.models_loaded = True
|
136 |
+
|
137 |
+
# Créer deux colonnes pour l'upload et le bouton
|
138 |
+
col_upload, col_button = st.columns([3, 1])
|
139 |
+
|
140 |
+
with col_upload:
|
141 |
+
uploaded_files = st.file_uploader(
|
142 |
+
"Röntgenbilder hochladen",
|
143 |
+
type=['png', 'jpg', 'jpeg'],
|
144 |
+
accept_multiple_files=True,
|
145 |
+
label_visibility="collapsed"
|
146 |
+
)
|
147 |
+
|
148 |
+
# Bouton d'analyse dans la deuxième colonne
|
149 |
+
with col_button:
|
150 |
+
analyze_clicked = st.button("📋 Analysieren", key="analyze_btn", disabled=not uploaded_files)
|
151 |
+
|
152 |
+
# Analyse des images si le bouton est cliqué
|
153 |
+
if uploaded_files and analyze_clicked:
|
154 |
+
col1, col2 = st.columns([1, 1])
|
155 |
+
|
156 |
+
for idx, uploaded_file in enumerate(uploaded_files):
|
157 |
+
image = Image.open(uploaded_file)
|
158 |
+
|
159 |
+
# Analyse avec KnochenAuge (localisierung)
|
160 |
+
predictions = st.session_state.models["KnochenAuge"](image)
|
161 |
+
fractures_found = any(p['label'].lower() == 'fracture' and p['score'] > 0.6 for p in predictions)
|
162 |
|
163 |
+
# Afficher uniquement si des fractures sont détectées
|
164 |
+
if fractures_found:
|
165 |
+
with col1 if idx % 2 == 0 else col2:
|
166 |
+
result_image = image.copy()
|
167 |
+
result_image = draw_boxes(result_image, predictions)
|
168 |
+
st.image(result_image, caption=f"Bild {idx + 1}", use_column_width=True)
|
169 |
+
|
170 |
+
# Analyse KnochenWächter et RöntgenMeister
|
171 |
+
pred_wachter = st.session_state.models["KnochenWächter"](image)[0]
|
172 |
+
pred_meister = st.session_state.models["RöntgenMeister"](image)[0]
|
173 |
+
|
174 |
+
if pred_wachter['score'] > 0.6 or pred_meister['score'] > 0.6:
|
175 |
+
st.markdown(f"""
|
176 |
+
<div class='result-box'>
|
177 |
+
<span style='color: #2563eb'>KnochenWächter:</span> {pred_wachter['score']:.1%}<br>
|
178 |
+
<span style='color: #2563eb'>RöntgenMeister:</span> {pred_meister['score']:.1%}
|
179 |
+
</div>
|
180 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
+
# Script pour la synchronisation du thème
|
183 |
st.markdown("""
|
184 |
<script>
|
|
|
185 |
function updateTheme(isDark) {
|
186 |
document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
|
|
|
|
|
187 |
const root = document.documentElement;
|
188 |
if (isDark) {
|
189 |
root.style.setProperty('--background-color', '#1f2937');
|
|
|
196 |
}
|
197 |
}
|
198 |
|
|
|
199 |
window.addEventListener('message', function(e) {
|
200 |
if (e.data.type === 'theme-change') {
|
201 |
updateTheme(e.data.theme === 'dark');
|
202 |
}
|
203 |
});
|
204 |
|
|
|
205 |
updateTheme(window.matchMedia('(prefers-color-scheme: dark)').matches);
|
206 |
</script>
|
207 |
""", unsafe_allow_html=True)
|