Eakempreet commited on
Commit
9cebea9
·
1 Parent(s): 12bc208

Serve HUD from FastAPI + lock CORS to HF Space URL

Browse files
Files changed (2) hide show
  1. app/main.py +4 -1
  2. frontend/atas_hud_v11.html +1 -1
app/main.py CHANGED
@@ -31,6 +31,7 @@ main.py
31
  from fastapi import FastAPI
32
  from fastapi import UploadFile, File, Form
33
  from fastapi.middleware.cors import CORSMiddleware
 
34
  import tempfile
35
  import os
36
  from src.classifier import predict_aircraft
@@ -52,10 +53,12 @@ app = FastAPI()
52
  # allow_headers=["*"] → accept any headers the browser sends with the request
53
  app.add_middleware(
54
  CORSMiddleware,
55
- allow_origins=["*"],
56
  allow_methods=["*"],
57
  allow_headers=["*"],
58
  )
 
 
59
 
60
 
61
  # Function to take the inputs
 
31
  from fastapi import FastAPI
32
  from fastapi import UploadFile, File, Form
33
  from fastapi.middleware.cors import CORSMiddleware
34
+ from fastapi.responses import FileResponse
35
  import tempfile
36
  import os
37
  from src.classifier import predict_aircraft
 
53
  # allow_headers=["*"] → accept any headers the browser sends with the request
54
  app.add_middleware(
55
  CORSMiddleware,
56
+ allow_origins=["https://eakempreet-atas.hf.space"],
57
  allow_methods=["*"],
58
  allow_headers=["*"],
59
  )
60
+ # Now that the HUD is served from the same Space, no other origin needs access
61
+ # This prevents random websites from hitting your /analyze endpoint
62
 
63
 
64
  # Function to take the inputs
frontend/atas_hud_v11.html CHANGED
@@ -584,7 +584,7 @@ async function startSimulation() {
584
 
585
  try {
586
  // 4. Fire to FastAPI Backend
587
- const response = await fetch('http://localhost:8000/analyze', {
588
  method: 'POST',
589
  body: formData
590
  });
 
584
 
585
  try {
586
  // 4. Fire to FastAPI Backend
587
+ const response = await fetch('https://eakempreet-atas.hf.space/analyze', {
588
  method: 'POST',
589
  body: formData
590
  });