yassonee commited on
Commit
8b75131
·
verified ·
1 Parent(s): 6f17dfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -61
app.py CHANGED
@@ -3,6 +3,42 @@ from transformers import pipeline
3
  from PIL import Image, ImageDraw
4
  import numpy as np
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  # Configuration de la page
7
  st.set_page_config(
8
  page_title="Fraktur Detektion",
@@ -10,22 +46,8 @@ st.set_page_config(
10
  initial_sidebar_state="collapsed"
11
  )
12
 
13
- # Détection de Microsoft Edge et styles
14
  st.markdown("""
15
- <script>
16
- function detectEdge() {
17
- if (navigator.userAgent.indexOf("Edge") > -1) {
18
- document.body.innerHTML += `
19
- <div style="position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
20
- background: #ffeb3b; padding: 10px; border-radius: 5px; z-index: 9999;
21
- box-shadow: 0 2px 4px rgba(0,0,0,0.2);">
22
- ⚠️ Für die beste Erfahrung verwenden Sie bitte Chrome, Firefox oder Safari.
23
- </div>`;
24
- }
25
- }
26
- window.addEventListener('load', detectEdge);
27
- </script>
28
-
29
  <style>
30
  .stApp {
31
  background: #f0f2f5 !important;
@@ -122,36 +144,23 @@ st.markdown("""
122
  display: none !important;
123
  }
124
 
125
- /* Animation de chargement personnalisée */
126
- .loading {
127
- display: flex;
128
- align-items: center;
129
- justify-content: center;
130
- padding: 1rem;
131
- background: rgba(255,255,255,0.9);
132
- border-radius: 8px;
133
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
134
- margin: 1rem 0;
135
- }
136
-
137
- .loading-text {
138
- color: #1a1a1a;
139
- font-weight: 500;
140
- margin-left: 0.5rem;
141
  }
142
  </style>
143
  """, unsafe_allow_html=True)
144
 
145
- # Fonction de chargement des modèles avec cache
146
  @st.cache_resource(show_spinner=True)
147
  def load_models():
148
- with st.spinner('Modelle werden geladen...'):
149
- return {
150
- "KnochenAuge": pipeline("object-detection", model="D3STRON/bone-fracture-detr"),
151
- "KnochenWächter": pipeline("image-classification", model="Heem2/bone-fracture-detection-using-xray"),
152
- "RöntgenMeister": pipeline("image-classification",
153
- model="nandodeomkar/autotrain-fracture-detection-using-google-vit-base-patch-16-54382127388")
154
- }
155
 
156
  def translate_label(label):
157
  translations = {
@@ -213,30 +222,27 @@ def draw_boxes(image, predictions):
213
 
214
  def main():
215
  try:
216
- # Initialisation des modèles avec indicateur de chargement
217
- st.markdown("""
218
- <div class="loading">
219
- <div class="loading-text">Anwendung wird initialisiert...</div>
220
- </div>
221
- """, unsafe_allow_html=True)
222
 
223
- models = load_models()
 
 
 
 
 
224
 
225
- # Interface principale
226
- with st.container():
227
- st.write("### 📤 Röntgenbild hochladen")
228
- uploaded_file = st.file_uploader("Bild auswählen", type=['png', 'jpg', 'jpeg'], label_visibility="collapsed")
229
-
230
- col1, col2 = st.columns([2, 1])
231
- with col1:
232
- conf_threshold = st.slider(
233
- "Konfidenzschwelle",
234
- min_value=0.0, max_value=1.0,
235
- value=0.60, step=0.05,
236
- label_visibility="visible"
237
- )
238
- with col2:
239
- analyze_button = st.button("Analysieren")
240
 
241
  if uploaded_file and analyze_button:
242
  with st.spinner("Bild wird analysiert..."):
@@ -311,6 +317,7 @@ def main():
311
  else:
312
  st.write("#### 🖼️ Röntgenbild")
313
  st.image(image, use_container_width=True)
 
314
  except Exception as e:
315
  st.error(f"Ein Fehler ist aufgetreten: {str(e)}")
316
 
 
3
  from PIL import Image, ImageDraw
4
  import numpy as np
5
 
6
+ # Configuration WebSocket pour Edge
7
+ st.markdown("""
8
+ <script>
9
+ if (navigator.userAgent.indexOf("Edge") > -1) {
10
+ // Désactiver complètement les WebSockets sur Edge
11
+ window.WebSocket = function() {
12
+ return {
13
+ send: function() {},
14
+ close: function() {},
15
+ addEventListener: function() {}
16
+ };
17
+ };
18
+
19
+ // Notification pour les utilisateurs Edge
20
+ document.addEventListener('DOMContentLoaded', function() {
21
+ const notice = document.createElement('div');
22
+ notice.style.cssText = `
23
+ position: fixed;
24
+ top: 10px;
25
+ left: 50%;
26
+ transform: translateX(-50%);
27
+ background: #ffeb3b;
28
+ padding: 10px 20px;
29
+ border-radius: 5px;
30
+ z-index: 9999;
31
+ box-shadow: 0 2px 4px rgba(0,0,0,0.2);
32
+ text-align: center;
33
+ font-weight: 500;
34
+ `;
35
+ notice.innerHTML = '⚠️ Für die beste Erfahrung verwenden Sie bitte Chrome, Firefox oder Safari.';
36
+ document.body.appendChild(notice);
37
+ });
38
+ }
39
+ </script>
40
+ """, unsafe_allow_html=True)
41
+
42
  # Configuration de la page
43
  st.set_page_config(
44
  page_title="Fraktur Detektion",
 
46
  initial_sidebar_state="collapsed"
47
  )
48
 
49
+ # Styles
50
  st.markdown("""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  <style>
52
  .stApp {
53
  background: #f0f2f5 !important;
 
144
  display: none !important;
145
  }
146
 
147
+ /* Loading spinner */
148
+ .stSpinner {
149
+ text-align: center;
150
+ max-width: 50%;
151
+ margin: 0 auto;
 
 
 
 
 
 
 
 
 
 
 
152
  }
153
  </style>
154
  """, unsafe_allow_html=True)
155
 
 
156
  @st.cache_resource(show_spinner=True)
157
  def load_models():
158
+ return {
159
+ "KnochenAuge": pipeline("object-detection", model="D3STRON/bone-fracture-detr"),
160
+ "KnochenWächter": pipeline("image-classification", model="Heem2/bone-fracture-detection-using-xray"),
161
+ "RöntgenMeister": pipeline("image-classification",
162
+ model="nandodeomkar/autotrain-fracture-detection-using-google-vit-base-patch-16-54382127388")
163
+ }
 
164
 
165
  def translate_label(label):
166
  translations = {
 
222
 
223
  def main():
224
  try:
225
+ with st.spinner("Modelle werden geladen..."):
226
+ models = load_models()
 
 
 
 
227
 
228
+ st.write("### 📤 Röntgenbild hochladen")
229
+ uploaded_file = st.file_uploader(
230
+ "Bild auswählen",
231
+ type=['png', 'jpg', 'jpeg'],
232
+ label_visibility="collapsed"
233
+ )
234
 
235
+ col1, col2 = st.columns([2, 1])
236
+ with col1:
237
+ conf_threshold = st.slider(
238
+ "Konfidenzschwelle",
239
+ min_value=0.0,
240
+ max_value=1.0,
241
+ value=0.60,
242
+ step=0.05
243
+ )
244
+ with col2:
245
+ analyze_button = st.button("Analysieren", use_container_width=True)
 
 
 
 
246
 
247
  if uploaded_file and analyze_button:
248
  with st.spinner("Bild wird analysiert..."):
 
317
  else:
318
  st.write("#### 🖼️ Röntgenbild")
319
  st.image(image, use_container_width=True)
320
+
321
  except Exception as e:
322
  st.error(f"Ein Fehler ist aufgetreten: {str(e)}")
323