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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +168 -44
app.py CHANGED
@@ -4,23 +4,154 @@ from PIL import Image, ImageDraw
4
  import numpy as np
5
 
6
  # Configuration de la page
7
- if 'page_config' not in st.session_state:
8
- st.set_page_config(
9
- page_title="Fraktur Detektion",
10
- layout="wide",
11
- initial_sidebar_state="collapsed",
12
- menu_items=None
13
- )
14
- st.session_state.page_config = True
15
 
16
- @st.cache_resource
17
- def load_models():
18
- return {
19
- "KnochenAuge": pipeline("object-detection", model="D3STRON/bone-fracture-detr"),
20
- "KnochenWächter": pipeline("image-classification", model="Heem2/bone-fracture-detection-using-xray"),
21
- "RöntgenMeister": pipeline("image-classification",
22
- model="nandodeomkar/autotrain-fracture-detection-using-google-vit-base-patch-16-54382127388")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  def translate_label(label):
26
  translations = {
@@ -81,38 +212,31 @@ def draw_boxes(image, predictions):
81
  return result_image
82
 
83
  def main():
84
- st.markdown("""
85
- <style>
86
- .stApp {background: #f0f2f5}
87
- div[data-testid="stToolbar"] {display: none}
88
- #MainMenu {visibility: hidden}
89
- footer {visibility: hidden}
90
- header {visibility: hidden}
91
- .result-box {
92
- background: #f8f9fa;
93
- padding: 0.75rem;
94
- border-radius: 8px;
95
- margin: 0.5rem 0;
96
- border: 1px solid #e9ecef;
97
- }
98
- </style>
99
- """, unsafe_allow_html=True)
100
-
101
  try:
102
- models = load_models()
 
 
 
 
 
103
 
104
- st.write("### 📤 Röntgenbild hochladen")
105
- uploaded_file = st.file_uploader("Bild auswählen", type=['png', 'jpg', 'jpeg'], label_visibility="collapsed")
106
 
107
- col1, col2 = st.columns([2, 1])
108
- with col1:
109
- conf_threshold = st.slider(
110
- "Konfidenzschwelle",
111
- min_value=0.0, max_value=1.0,
112
- value=0.60, step=0.05
113
- )
114
- with col2:
115
- analyze_button = st.button("Analysieren")
 
 
 
 
 
 
116
 
117
  if uploaded_file and analyze_button:
118
  with st.spinner("Bild wird analysiert..."):
 
4
  import numpy as np
5
 
6
  # Configuration de la page
7
+ st.set_page_config(
8
+ page_title="Fraktur Detektion",
9
+ layout="wide",
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;
32
+ }
33
+
34
+ .block-container {
35
+ padding-top: 1rem !important;
36
+ padding-bottom: 1rem !important;
37
+ max-width: 1400px !important;
38
+ }
39
+
40
+ .upload-container {
41
+ background: white;
42
+ padding: 1.5rem;
43
+ border-radius: 10px;
44
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
45
+ margin-bottom: 1rem;
46
+ text-align: center;
47
+ }
48
+
49
+ .results-container {
50
+ background: white;
51
+ padding: 1.5rem;
52
+ border-radius: 10px;
53
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
54
+ }
55
+
56
+ .result-box {
57
+ background: #f8f9fa;
58
+ padding: 0.75rem;
59
+ border-radius: 8px;
60
+ margin: 0.5rem 0;
61
+ border: 1px solid #e9ecef;
62
+ }
63
+
64
+ h1, h2, h3, h4, p {
65
+ color: #1a1a1a !important;
66
+ margin: 0.5rem 0 !important;
67
+ }
68
+
69
+ .stImage {
70
+ background: white;
71
+ padding: 0.5rem;
72
+ border-radius: 8px;
73
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
74
+ }
75
+
76
+ .stImage > img {
77
+ max-height: 300px !important;
78
+ width: auto !important;
79
+ margin: 0 auto !important;
80
+ display: block !important;
81
+ }
82
+
83
+ [data-testid="stFileUploader"] {
84
+ width: 100% !important;
85
+ }
86
+
87
+ .stFileUploaderFileName {
88
+ color: #1a1a1a !important;
89
  }
90
+
91
+ .stButton > button {
92
+ width: 200px;
93
+ background-color: #f8f9fa !important;
94
+ color: #1a1a1a !important;
95
+ border: 1px solid #e9ecef !important;
96
+ padding: 0.5rem 1rem !important;
97
+ border-radius: 5px !important;
98
+ transition: all 0.3s ease !important;
99
+ }
100
+
101
+ .stButton > button:hover {
102
+ background-color: #e9ecef !important;
103
+ transform: translateY(-1px);
104
+ }
105
+
106
+ #MainMenu, footer, header {
107
+ display: none !important;
108
+ }
109
+
110
+ /* Fix pour Edge */
111
+ iframe {
112
+ visibility: visible !important;
113
+ display: block !important;
114
+ }
115
+
116
+ /* Cache les erreurs de connexion */
117
+ .streamlit-expanderContent {
118
+ display: none !important;
119
+ }
120
+
121
+ .element-container:has(>.stAlert) {
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 = {
 
212
  return result_image
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..."):