altawil commited on
Commit
636bae4
·
verified ·
1 Parent(s): dd92815

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -79
app.py CHANGED
@@ -128,7 +128,6 @@ async def startup_event():
128
  global MODEL
129
  logging.info("🚗 Server starting up...")
130
  logging.info(f"Using device: {DEVICE}")
131
- # MODEL = load_and_prepare_model(model_config, DEVICE)
132
  MODEL = load_and_prepare_model(DEVICE)
133
  if MODEL:
134
  logging.info("✅ Model loaded successfully. Server is ready!")
@@ -138,21 +137,19 @@ async def startup_event():
138
  # ==============================================================================
139
  # 6. نقاط النهاية الرئيسية (API Endpoints)
140
  # ==============================================================================
141
-
142
  @app.get("/", response_class=HTMLResponse, include_in_schema=False, tags=["General"])
143
  async def root():
144
  """
145
- يعرض صفحة رئيسية احترافية وتفاعلية لواجهة برمجة التطبيقات.
 
146
  """
147
- # الحصول على عدد الجلسات النشطة حاليًا
148
  active_sessions_count = len(SESSIONS)
149
 
150
- # تحديد لون حالة النظام
151
- status_color = "#4CAF50" # أخضر
152
- status_text = "يعمل بنجاح"
153
  if MODEL is None:
154
- status_color = "#F44336" # أحمر
155
- status_text = "خطأ: النموذج غير محمل"
156
 
157
  html_content = f"""
158
  <!DOCTYPE html>
@@ -160,151 +157,175 @@ async def root():
160
  <head>
161
  <meta charset="UTF-8">
162
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
163
- <title>🚗 Baseer Self-Driving API</title>
164
  <style>
165
- @import url('https://fonts.googleapis.com/css2?family=Tajawal:wght@400;700&display=swap');
166
 
167
  :root {{
168
- --primary-color: #4a69bd;
169
- --secondary-color: #6a89cc;
170
- --text-color: #333;
171
- --bg-color: #f4f7f6;
172
- --panel-bg: #ffffff;
173
- --shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
 
174
  }}
175
 
176
  body {{
177
- font-family: 'Tajawal', sans-serif;
178
- background-color: var(--bg-color);
179
- color: var(--text-color);
 
180
  margin: 0;
181
  display: flex;
182
  justify-content: center;
183
  align-items: center;
184
  min-height: 100vh;
185
  padding: 20px;
 
186
  }}
187
 
188
  .container {{
189
- background: var(--panel-bg);
190
- border-radius: 20px;
191
- padding: 40px;
192
- box-shadow: var(--shadow);
 
193
  text-align: center;
194
- max-width: 700px;
195
  width: 100%;
196
- border-top: 5px solid var(--primary-color);
 
 
197
  }}
198
-
199
  .logo {{
200
- font-size: 4rem;
201
- margin-bottom: 15px;
202
- animation: car-drive 3s ease-in-out infinite;
 
203
  }}
204
 
205
- @keyframes car-drive {{
206
- 0% {{ transform: translateX(-20px); }}
207
- 50% {{ transform: translateX(20px); }}
208
- 100% {{ transform: translateX(-20px); }}
209
  }}
210
 
211
  h1 {{
212
- font-size: 2.8rem;
213
- font-weight: 700;
214
- color: var(--primary-color);
215
- margin-bottom: 10px;
 
216
  }}
217
 
218
  .subtitle {{
219
- font-size: 1.2rem;
220
- color: #777;
221
  margin-bottom: 25px;
222
  }}
223
 
224
  .status-badge {{
225
- display: inline-block;
226
- background-color: {status_color};
227
- color: white;
228
- padding: 10px 20px;
229
- border-radius: 25px;
 
 
 
230
  font-weight: bold;
231
- margin-bottom: 30px;
232
- font-size: 1rem;
 
233
  }}
234
 
235
  .stats-grid {{
236
  display: grid;
237
  grid-template-columns: 1fr 1fr;
238
- gap: 20px;
239
- margin-bottom: 30px;
240
  }}
241
 
242
  .stat-card {{
243
- background: #f8f9fa;
244
- padding: 20px;
245
- border-radius: 15px;
 
 
 
 
 
 
246
  }}
247
 
248
  .stat-number {{
249
- font-size: 2.5rem;
250
  font-weight: 700;
251
- color: var(--primary-color);
252
  }}
253
 
254
  .stat-label {{
255
  font-size: 1rem;
256
- color: #666;
257
  margin-top: 5px;
258
  }}
259
 
260
  .button-group {{
261
  display: flex;
262
- gap: 15px;
263
  justify-content: center;
264
  }}
265
 
266
  .btn {{
267
- padding: 14px 28px;
268
- border-radius: 30px;
269
  text-decoration: none;
270
- font-weight: bold;
271
- font-size: 1rem;
272
  transition: all 0.3s ease;
273
- border: 2px solid transparent;
274
  cursor: pointer;
 
 
275
  }}
276
 
277
  .btn-primary {{
278
- background: var(--primary-color);
279
- color: white;
 
280
  }}
281
-
282
  .btn-primary:hover {{
283
- background: var(--secondary-color);
284
- transform: translateY(-3px);
285
  }}
286
 
287
  .btn-secondary {{
288
  background: transparent;
289
- color: var(--primary-color);
290
- border-color: var(--primary-color);
291
  }}
292
 
293
  .btn-secondary:hover {{
294
- background: var(--primary-color);
295
- color: white;
296
- transform: translateY(-3px);
297
  }}
298
 
299
  </style>
300
  </head>
301
  <body>
302
  <div class="container">
303
- <div class="logo">🚗</div>
304
- <h1>Baseer Self-Driving API</h1>
305
- <p class="subtitle">واجهة برمجية متقدمة للقيادة الذاتية</p>
306
 
307
- <div class="status-badge">{status_text}</div>
 
 
 
308
 
309
  <div class="stats-grid">
310
  <div class="stat-card">
@@ -312,13 +333,13 @@ async def root():
312
  <div class="stat-label">الجلسات النشطة</div>
313
  </div>
314
  <div class="stat-card">
315
- <div class="stat-number">1.1.0</div>
316
- <div class="stat-label">إصدار الـ API</div>
317
  </div>
318
  </div>
319
 
320
  <div class="button-group">
321
- <a href="/docs" target="_blank" class="btn btn-primary">📚 التوثيق التفاعلي (Docs)</a>
322
  <a href="/sessions" target="_blank" class="btn btn-secondary">📊 عرض الجلسات</a>
323
  </div>
324
  </div>
@@ -326,7 +347,7 @@ async def root():
326
  </html>
327
  """
328
  return HTMLResponse(content=html_content)
329
-
330
  @app.post("/start_session", summary="Start a new driving session", tags=["Session Management"])
331
  def start_session():
332
  session_id = str(uuid.uuid4())
 
128
  global MODEL
129
  logging.info("🚗 Server starting up...")
130
  logging.info(f"Using device: {DEVICE}")
 
131
  MODEL = load_and_prepare_model(DEVICE)
132
  if MODEL:
133
  logging.info("✅ Model loaded successfully. Server is ready!")
 
137
  # ==============================================================================
138
  # 6. نقاط النهاية الرئيسية (API Endpoints)
139
  # ==============================================================================
 
140
  @app.get("/", response_class=HTMLResponse, include_in_schema=False, tags=["General"])
141
  async def root():
142
  """
143
+ [النسخة الجذابة]
144
+ يعرض صفحة رئيسية احترافية وجذابة بصريًا لواجهة برمجة التطبيقات.
145
  """
 
146
  active_sessions_count = len(SESSIONS)
147
 
148
+ status_color = "#00ff7f" # SpringGreen
149
+ status_text = "متصل ويعمل"
 
150
  if MODEL is None:
151
+ status_color = "#ff4757" # Red
152
+ status_text = "خطأ: النموذج غير متاح"
153
 
154
  html_content = f"""
155
  <!DOCTYPE html>
 
157
  <head>
158
  <meta charset="UTF-8">
159
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
160
+ <title>🚗 Baseer - واجهة القيادة الذاتية</title>
161
  <style>
162
+ @import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;700;900&display=swap');
163
 
164
  :root {{
165
+ --bg-dark: #1a1a2e;
166
+ --panel-dark: #16213e;
167
+ --primary-accent: #0f3460;
168
+ --secondary-accent: #e94560;
169
+ --glow-color: #537895;
170
+ --text-light: #e0e0e0;
171
+ --text-header: #ffffff;
172
  }}
173
 
174
  body {{
175
+ font-family: 'Cairo', sans-serif;
176
+ background: var(--bg-dark);
177
+ background-image: linear-gradient(to right top, #1a1a2e, #1c1d32, #1f2037, #22233b, #252640);
178
+ color: var(--text-light);
179
  margin: 0;
180
  display: flex;
181
  justify-content: center;
182
  align-items: center;
183
  min-height: 100vh;
184
  padding: 20px;
185
+ overflow: hidden;
186
  }}
187
 
188
  .container {{
189
+ background: rgba(22, 33, 62, 0.85);
190
+ backdrop-filter: blur(15px);
191
+ border-radius: 25px;
192
+ padding: 40px 50px;
193
+ box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
194
  text-align: center;
195
+ max-width: 750px;
196
  width: 100%;
197
+ border: 1px solid rgba(255, 255, 255, 0.1);
198
+ position: relative;
199
+ z-index: 1;
200
  }}
201
+
202
  .logo {{
203
+ font-size: 5rem;
204
+ margin-bottom: 10px;
205
+ text-shadow: 0 0 15px var(--glow-color);
206
+ animation: float 4s ease-in-out infinite;
207
  }}
208
 
209
+ @keyframes float {{
210
+ 0% {{ transform: translateY(0px); }}
211
+ 50% {{ transform: translateY(-15px); }}
212
+ 100% {{ transform: translateY(0px); }}
213
  }}
214
 
215
  h1 {{
216
+ font-size: 3rem;
217
+ font-weight: 900;
218
+ color: var(--text-header);
219
+ margin-bottom: 5px;
220
+ letter-spacing: 1px;
221
  }}
222
 
223
  .subtitle {{
224
+ font-size: 1.3rem;
225
+ color: #a7a9be;
226
  margin-bottom: 25px;
227
  }}
228
 
229
  .status-badge {{
230
+ display: inline-flex;
231
+ align-items: center;
232
+ gap: 10px;
233
+ background-color: rgba(255, 255, 255, 0.05);
234
+ border: 1px solid {status_color};
235
+ color: {status_color};
236
+ padding: 10px 22px;
237
+ border-radius: 50px;
238
  font-weight: bold;
239
+ margin-bottom: 35px;
240
+ font-size: 1.1rem;
241
+ box-shadow: 0 0 15px {status_color}33;
242
  }}
243
 
244
  .stats-grid {{
245
  display: grid;
246
  grid-template-columns: 1fr 1fr;
247
+ gap: 25px;
248
+ margin-bottom: 40px;
249
  }}
250
 
251
  .stat-card {{
252
+ background: var(--primary-accent);
253
+ padding: 25px;
254
+ border-radius: 20px;
255
+ transition: transform 0.3s ease, box-shadow 0.3s ease;
256
+ }}
257
+
258
+ .stat-card:hover {{
259
+ transform: scale(1.05);
260
+ box-shadow: 0 0 25px var(--secondary-accent)44;
261
  }}
262
 
263
  .stat-number {{
264
+ font-size: 3rem;
265
  font-weight: 700;
266
+ color: var(--secondary-accent);
267
  }}
268
 
269
  .stat-label {{
270
  font-size: 1rem;
271
+ color: #a7a9be;
272
  margin-top: 5px;
273
  }}
274
 
275
  .button-group {{
276
  display: flex;
277
+ gap: 20px;
278
  justify-content: center;
279
  }}
280
 
281
  .btn {{
282
+ padding: 15px 35px;
283
+ border-radius: 50px;
284
  text-decoration: none;
285
+ font-weight: 700;
286
+ font-size: 1.1rem;
287
  transition: all 0.3s ease;
288
+ border: none;
289
  cursor: pointer;
290
+ position: relative;
291
+ overflow: hidden;
292
  }}
293
 
294
  .btn-primary {{
295
+ background: var(--secondary-accent);
296
+ color: var(--text-header);
297
+ box-shadow: 0 5px 15px {status_color}44;
298
  }}
299
+
300
  .btn-primary:hover {{
301
+ box-shadow: 0 8px 25px {status_color}66;
302
+ transform: translateY(-3px);
303
  }}
304
 
305
  .btn-secondary {{
306
  background: transparent;
307
+ color: var(--text-light);
308
+ border: 2px solid var(--glow-color);
309
  }}
310
 
311
  .btn-secondary:hover {{
312
+ background: var(--glow-color);
313
+ color: var(--text-header);
314
+ border-color: var(--glow-color);
315
  }}
316
 
317
  </style>
318
  </head>
319
  <body>
320
  <div class="container">
321
+ <div class="logo">🚀</div>
322
+ <h1>بصيـر API</h1>
323
+ <p class="subtitle">مستقبل القيادة الذاتية بين يديك</p>
324
 
325
+ <div class="status-badge">
326
+ <span style="width: 12px; height: 12px; background-color: {status_color}; border-radius: 50%;"></span>
327
+ <span>{status_text}</span>
328
+ </div>
329
 
330
  <div class="stats-grid">
331
  <div class="stat-card">
 
333
  <div class="stat-label">الجلسات النشطة</div>
334
  </div>
335
  <div class="stat-card">
336
+ <div class="stat-number">1.1</div>
337
+ <div class="stat-label">الإصدار</div>
338
  </div>
339
  </div>
340
 
341
  <div class="button-group">
342
+ <a href="/docs" target="_blank" class="btn btn-primary">📚 التوثيق التفاعلي</a>
343
  <a href="/sessions" target="_blank" class="btn btn-secondary">📊 عرض الجلسات</a>
344
  </div>
345
  </div>
 
347
  </html>
348
  """
349
  return HTMLResponse(content=html_content)
350
+
351
  @app.post("/start_session", summary="Start a new driving session", tags=["Session Management"])
352
  def start_session():
353
  session_id = str(uuid.uuid4())