altawil commited on
Commit
8176c5b
·
verified ·
1 Parent(s): adff7c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +183 -8
app.py CHANGED
@@ -6,6 +6,7 @@ import cv2
6
  import torch
7
  import numpy as np
8
  from fastapi import FastAPI, HTTPException
 
9
  from pydantic import BaseModel
10
  from torchvision import transforms
11
  from typing import List, Dict, Any, Optional
@@ -171,17 +172,191 @@ def encode_image_to_base64(image: np.ndarray) -> str:
171
  return base64.b64encode(buffer).decode('utf-8')
172
 
173
  # ================== نقاط نهاية الـ API ==================
174
- @app.get("/")
175
  async def root():
176
  """
177
- نقطة البداية للـ API
178
  """
179
- return {
180
- "message": "InterFuser Self-Driving API",
181
- "version": "1.0.0",
182
- "status": "running",
183
- "active_sessions": len(SESSIONS)
184
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
 
186
  @app.post("/start_session", response_model=SessionResponse)
187
  async def start_session():
 
6
  import torch
7
  import numpy as np
8
  from fastapi import FastAPI, HTTPException
9
+ from fastapi.responses import HTMLResponse
10
  from pydantic import BaseModel
11
  from torchvision import transforms
12
  from typing import List, Dict, Any, Optional
 
172
  return base64.b64encode(buffer).decode('utf-8')
173
 
174
  # ================== نقاط نهاية الـ API ==================
175
+ @app.get("/", response_class=HTMLResponse)
176
  async def root():
177
  """
178
+ الصفحة الرئيسية للـ API
179
  """
180
+ html_content = f"""
181
+ <!DOCTYPE html>
182
+ <html dir="rtl" lang="ar">
183
+ <head>
184
+ <meta charset="UTF-8">
185
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
186
+ <title>🚗 Baseer Self-Driving API</title>
187
+ <style>
188
+ * {{
189
+ margin: 0;
190
+ padding: 0;
191
+ box-sizing: border-box;
192
+ }}
193
+ body {{
194
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
195
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
196
+ min-height: 100vh;
197
+ display: flex;
198
+ align-items: center;
199
+ justify-content: center;
200
+ padding: 20px;
201
+ }}
202
+ .container {{
203
+ background: rgba(255, 255, 255, 0.95);
204
+ backdrop-filter: blur(10px);
205
+ border-radius: 20px;
206
+ padding: 40px;
207
+ box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
208
+ text-align: center;
209
+ max-width: 600px;
210
+ width: 100%;
211
+ }}
212
+ .logo {{
213
+ font-size: 4rem;
214
+ margin-bottom: 20px;
215
+ animation: bounce 2s infinite;
216
+ }}
217
+ @keyframes bounce {{
218
+ 0%, 20%, 50%, 80%, 100% {{ transform: translateY(0); }}
219
+ 40% {{ transform: translateY(-10px); }}
220
+ 60% {{ transform: translateY(-5px); }}
221
+ }}
222
+ h1 {{
223
+ color: #333;
224
+ margin-bottom: 10px;
225
+ font-size: 2.5rem;
226
+ }}
227
+ .subtitle {{
228
+ color: #666;
229
+ margin-bottom: 30px;
230
+ font-size: 1.2rem;
231
+ }}
232
+ .status {{
233
+ display: inline-block;
234
+ background: #4CAF50;
235
+ color: white;
236
+ padding: 8px 16px;
237
+ border-radius: 20px;
238
+ margin: 10px 0;
239
+ font-weight: bold;
240
+ }}
241
+ .stats {{
242
+ display: grid;
243
+ grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
244
+ gap: 20px;
245
+ margin: 30px 0;
246
+ }}
247
+ .stat-card {{
248
+ background: #f8f9fa;
249
+ padding: 20px;
250
+ border-radius: 15px;
251
+ border-left: 4px solid #667eea;
252
+ }}
253
+ .stat-number {{
254
+ font-size: 2rem;
255
+ font-weight: bold;
256
+ color: #667eea;
257
+ }}
258
+ .stat-label {{
259
+ color: #666;
260
+ margin-top: 5px;
261
+ }}
262
+ .buttons {{
263
+ display: flex;
264
+ gap: 15px;
265
+ justify-content: center;
266
+ flex-wrap: wrap;
267
+ margin-top: 30px;
268
+ }}
269
+ .btn {{
270
+ display: inline-block;
271
+ padding: 12px 24px;
272
+ border-radius: 25px;
273
+ text-decoration: none;
274
+ font-weight: bold;
275
+ transition: all 0.3s ease;
276
+ border: none;
277
+ cursor: pointer;
278
+ }}
279
+ .btn-primary {{
280
+ background: #667eea;
281
+ color: white;
282
+ }}
283
+ .btn-secondary {{
284
+ background: #6c757d;
285
+ color: white;
286
+ }}
287
+ .btn:hover {{
288
+ transform: translateY(-2px);
289
+ box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
290
+ }}
291
+ .features {{
292
+ text-align: right;
293
+ margin-top: 30px;
294
+ padding: 20px;
295
+ background: #f8f9fa;
296
+ border-radius: 15px;
297
+ }}
298
+ .features h3 {{
299
+ color: #333;
300
+ margin-bottom: 15px;
301
+ }}
302
+ .features ul {{
303
+ list-style: none;
304
+ padding: 0;
305
+ }}
306
+ .features li {{
307
+ padding: 5px 0;
308
+ color: #666;
309
+ }}
310
+ .features li:before {{
311
+ content: "✅ ";
312
+ margin-left: 10px;
313
+ }}
314
+ </style>
315
+ </head>
316
+ <body>
317
+ <div class="container">
318
+ <div class="logo">🚗</div>
319
+ <h1>Baseer Self-Driving API</h1>
320
+ <p class="subtitle">نظام القيادة الذاتية المتقدم</p>
321
+
322
+ <div class="status">🟢 يعمل بنجاح</div>
323
+
324
+ <div class="stats">
325
+ <div class="stat-card">
326
+ <div class="stat-number">{len(SESSIONS)}</div>
327
+ <div class="stat-label">الجلسات النشطة</div>
328
+ </div>
329
+ <div class="stat-card">
330
+ <div class="stat-number">v1.0</div>
331
+ <div class="stat-label">الإصدار</div>
332
+ </div>
333
+ <div class="stat-card">
334
+ <div class="stat-number">FastAPI</div>
335
+ <div class="stat-label">التقنية</div>
336
+ </div>
337
+ </div>
338
+
339
+ <div class="buttons">
340
+ <a href="/docs" class="btn btn-primary">📚 توثيق API</a>
341
+ <a href="/sessions" class="btn btn-secondary">📊 الجلسات</a>
342
+ </div>
343
+
344
+ <div class="features">
345
+ <h3>🌟 الميزات الرئيسية</h3>
346
+ <ul>
347
+ <li>نموذج InterFuser للقيادة الذاتية</li>
348
+ <li>معالجة الصور في الوقت الفعلي</li>
349
+ <li>اكتشاف الكائنات المرورية</li>
350
+ <li>تحديد المسارات الذكية</li>
351
+ <li>واجهة RESTful سهلة الاستخدام</li>
352
+ <li>إدارة جلسات متعددة</li>
353
+ </ul>
354
+ </div>
355
+ </div>
356
+ </body>
357
+ </html>
358
+ """
359
+ return html_content
360
 
361
  @app.post("/start_session", response_model=SessionResponse)
362
  async def start_session():