Factor Studios commited on
Commit
10900fd
·
verified ·
1 Parent(s): c19f8ab

Update test_ai_integration.py

Browse files
Files changed (1) hide show
  1. test_ai_integration.py +95 -1
test_ai_integration.py CHANGED
@@ -370,12 +370,106 @@ def test_ai_integration():
370
 
371
  return components
372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
  if __name__ == "__main__":
374
  import logging
 
 
 
375
  logging.basicConfig(level=logging.INFO)
376
  logger = logging.getLogger(__name__)
377
 
 
 
 
378
  # Run as FastAPI server
379
  logger.info("Starting AI Integration Test Server...")
380
- uvicorn.run(app, host="0.0.0.0", port=8000)
 
 
 
 
381
 
 
370
 
371
  return components
372
 
373
+ def create_app():
374
+ """Create and configure the FastAPI application"""
375
+ from fastapi import FastAPI, File, UploadFile
376
+ from fastapi.responses import JSONResponse
377
+ import io
378
+ from PIL import Image
379
+
380
+ app = FastAPI(
381
+ title="AI Integration Test API",
382
+ description="WebSocket-based GPU storage with zero CPU memory usage",
383
+ version="1.0.0"
384
+ )
385
+
386
+ @app.on_event("startup")
387
+ async def startup_event():
388
+ """Initialize GPU components on server startup"""
389
+ global gpu_components
390
+ gpu_components = test_ai_integration()
391
+
392
+ @app.get("/")
393
+ async def root():
394
+ """Root endpoint showing system status"""
395
+ from electron_speed import drift_velocity
396
+ return {
397
+ "status": "running",
398
+ "speed": f"{drift_velocity:.2e} m/s",
399
+ "flip_flop_delay": "1.02e-15 s",
400
+ "max_frequency": "9.80e+14 Hz"
401
+ }
402
+
403
+ @app.post("/process")
404
+ async def process_image(image: UploadFile = File(...)):
405
+ """Process an image using WebSocket-based GPU acceleration"""
406
+ try:
407
+ contents = await image.read()
408
+ img = Image.open(io.BytesIO(contents)).convert('RGB')
409
+
410
+ # Process using initialized GPU components
411
+ with websocket_manager() as storage:
412
+ # Convert and store image
413
+ image_array = np.array(img)
414
+ storage.store_tensor("input_image", image_array)
415
+
416
+ # Run inference
417
+ if gpu_components and gpu_components.get('ai_accelerators'):
418
+ accelerator = gpu_components['ai_accelerators'][0]
419
+ result = accelerator.inference(
420
+ gpu_components['model_id'],
421
+ "input_image"
422
+ )
423
+
424
+ return JSONResponse({
425
+ "status": "success",
426
+ "result": result.tolist() if isinstance(result, np.ndarray) else result,
427
+ "processing_stats": {
428
+ "flip_flop_delay": "1.02e-15 s",
429
+ "max_frequency": "9.80e+14 Hz"
430
+ }
431
+ })
432
+ else:
433
+ raise ValueError("GPU components not initialized")
434
+
435
+ except Exception as e:
436
+ return JSONResponse(
437
+ status_code=500,
438
+ content={
439
+ "status": "error",
440
+ "message": str(e)
441
+ }
442
+ )
443
+
444
+ @app.get("/status")
445
+ async def get_status():
446
+ if not gpu_components:
447
+ return {"status": "not_initialized"}
448
+ return {
449
+ "status": "running",
450
+ "flip_flop_delay": "1.02e-15 s",
451
+ "max_frequency": "9.80e+14 Hz",
452
+ "model_loaded": gpu_components.get('model_id') is not None
453
+ }
454
+
455
+ return app
456
+
457
  if __name__ == "__main__":
458
  import logging
459
+ import uvicorn
460
+ from fastapi import FastAPI
461
+
462
  logging.basicConfig(level=logging.INFO)
463
  logger = logging.getLogger(__name__)
464
 
465
+ # Create the FastAPI app
466
+ app = create_app()
467
+
468
  # Run as FastAPI server
469
  logger.info("Starting AI Integration Test Server...")
470
+ uvicorn.run("test_ai_integration:create_app()",
471
+ host="0.0.0.0",
472
+ port=8000,
473
+ factory=True,
474
+ reload=True)
475