Spaces:
Sleeping
Sleeping
altawil
commited on
Update app.py
Browse files
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 |
-
|
| 152 |
-
status_text = "يعمل بنجاح"
|
| 153 |
if MODEL is None:
|
| 154 |
-
status_color = "#
|
| 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
|
| 164 |
<style>
|
| 165 |
-
@import url('https://fonts.googleapis.com/css2?family=
|
| 166 |
|
| 167 |
:root {{
|
| 168 |
-
--
|
| 169 |
-
--
|
| 170 |
-
--
|
| 171 |
-
--
|
| 172 |
-
--
|
| 173 |
-
--
|
|
|
|
| 174 |
}}
|
| 175 |
|
| 176 |
body {{
|
| 177 |
-
font-family: '
|
| 178 |
-
background
|
| 179 |
-
|
|
|
|
| 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:
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
|
|
|
| 193 |
text-align: center;
|
| 194 |
-
max-width:
|
| 195 |
width: 100%;
|
| 196 |
-
border
|
|
|
|
|
|
|
| 197 |
}}
|
| 198 |
-
|
| 199 |
.logo {{
|
| 200 |
-
font-size:
|
| 201 |
-
margin-bottom:
|
| 202 |
-
|
|
|
|
| 203 |
}}
|
| 204 |
|
| 205 |
-
@keyframes
|
| 206 |
-
0% {{ transform:
|
| 207 |
-
50% {{ transform:
|
| 208 |
-
100% {{ transform:
|
| 209 |
}}
|
| 210 |
|
| 211 |
h1 {{
|
| 212 |
-
font-size:
|
| 213 |
-
font-weight:
|
| 214 |
-
color: var(--
|
| 215 |
-
margin-bottom:
|
|
|
|
| 216 |
}}
|
| 217 |
|
| 218 |
.subtitle {{
|
| 219 |
-
font-size: 1.
|
| 220 |
-
color: #
|
| 221 |
margin-bottom: 25px;
|
| 222 |
}}
|
| 223 |
|
| 224 |
.status-badge {{
|
| 225 |
-
display: inline-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
border
|
|
|
|
|
|
|
|
|
|
| 230 |
font-weight: bold;
|
| 231 |
-
margin-bottom:
|
| 232 |
-
font-size: 1rem;
|
|
|
|
| 233 |
}}
|
| 234 |
|
| 235 |
.stats-grid {{
|
| 236 |
display: grid;
|
| 237 |
grid-template-columns: 1fr 1fr;
|
| 238 |
-
gap:
|
| 239 |
-
margin-bottom:
|
| 240 |
}}
|
| 241 |
|
| 242 |
.stat-card {{
|
| 243 |
-
background:
|
| 244 |
-
padding:
|
| 245 |
-
border-radius:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
}}
|
| 247 |
|
| 248 |
.stat-number {{
|
| 249 |
-
font-size:
|
| 250 |
font-weight: 700;
|
| 251 |
-
color: var(--
|
| 252 |
}}
|
| 253 |
|
| 254 |
.stat-label {{
|
| 255 |
font-size: 1rem;
|
| 256 |
-
color: #
|
| 257 |
margin-top: 5px;
|
| 258 |
}}
|
| 259 |
|
| 260 |
.button-group {{
|
| 261 |
display: flex;
|
| 262 |
-
gap:
|
| 263 |
justify-content: center;
|
| 264 |
}}
|
| 265 |
|
| 266 |
.btn {{
|
| 267 |
-
padding:
|
| 268 |
-
border-radius:
|
| 269 |
text-decoration: none;
|
| 270 |
-
font-weight:
|
| 271 |
-
font-size: 1rem;
|
| 272 |
transition: all 0.3s ease;
|
| 273 |
-
border:
|
| 274 |
cursor: pointer;
|
|
|
|
|
|
|
| 275 |
}}
|
| 276 |
|
| 277 |
.btn-primary {{
|
| 278 |
-
background: var(--
|
| 279 |
-
color:
|
|
|
|
| 280 |
}}
|
| 281 |
-
|
| 282 |
.btn-primary:hover {{
|
| 283 |
-
|
| 284 |
-
|
| 285 |
}}
|
| 286 |
|
| 287 |
.btn-secondary {{
|
| 288 |
background: transparent;
|
| 289 |
-
color: var(--
|
| 290 |
-
border
|
| 291 |
}}
|
| 292 |
|
| 293 |
.btn-secondary:hover {{
|
| 294 |
-
background: var(--
|
| 295 |
-
color:
|
| 296 |
-
|
| 297 |
}}
|
| 298 |
|
| 299 |
</style>
|
| 300 |
</head>
|
| 301 |
<body>
|
| 302 |
<div class="container">
|
| 303 |
-
<div class="logo"
|
| 304 |
-
<h1
|
| 305 |
-
<p class="subtitle"
|
| 306 |
|
| 307 |
-
<div class="status-badge">
|
|
|
|
|
|
|
|
|
|
| 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
|
| 316 |
-
<div class="stat-label"
|
| 317 |
</div>
|
| 318 |
</div>
|
| 319 |
|
| 320 |
<div class="button-group">
|
| 321 |
-
<a href="/docs" target="_blank" class="btn btn-primary">📚 التوثيق
|
| 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())
|