Spaces:
Sleeping
Sleeping
Feat: Add CORSMiddleware to FastAPI app for HF Space integration
Browse files- modal_whisper_app.py +19 -0
modal_whisper_app.py
CHANGED
@@ -10,6 +10,7 @@ import gradio.routes
|
|
10 |
from typing import Dict, List, Any, Optional # For type hinting results and Optional in Pydantic
|
11 |
from fastapi.responses import JSONResponse # For FastAPI endpoint
|
12 |
from fastapi import File, Body, UploadFile, Query # For FastAPI file uploads, request body parts, and query parameters
|
|
|
13 |
from pydantic import BaseModel # For FastAPI request body validation
|
14 |
import re # For parsing search results
|
15 |
import asyncio # For concurrent video processing
|
@@ -48,6 +49,24 @@ app = modal.App(name="video-analysis-gradio-pipeline") # New app name, using App
|
|
48 |
|
49 |
fastapi_app = FastAPI() # Initialize FastAPI app
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
# --- Modal Distributed Dictionary for Caching ---
|
52 |
video_analysis_cache = modal.Dict.from_name("video_analysis_cache", create_if_missing=True)
|
53 |
|
|
|
10 |
from typing import Dict, List, Any, Optional # For type hinting results and Optional in Pydantic
|
11 |
from fastapi.responses import JSONResponse # For FastAPI endpoint
|
12 |
from fastapi import File, Body, UploadFile, Query # For FastAPI file uploads, request body parts, and query parameters
|
13 |
+
from fastapi.middleware.cors import CORSMiddleware
|
14 |
from pydantic import BaseModel # For FastAPI request body validation
|
15 |
import re # For parsing search results
|
16 |
import asyncio # For concurrent video processing
|
|
|
49 |
|
50 |
fastapi_app = FastAPI() # Initialize FastAPI app
|
51 |
|
52 |
+
# Define allowed origins for CORS
|
53 |
+
origins = [
|
54 |
+
"https://agents-mcp-hackathon-video-mcp.hf.space", # Your Hugging Face Space
|
55 |
+
"http://localhost",
|
56 |
+
"http://localhost:7860", # Default Gradio local port
|
57 |
+
"http://127.0.0.1:7860", # Default Gradio local port
|
58 |
+
# You can add other origins if needed, e.g., your Modal app's direct URL if you access it directly
|
59 |
+
"https://jomasego--video-analysis-gradio-pipeline-main-asgi.modal.run"
|
60 |
+
]
|
61 |
+
|
62 |
+
fastapi_app.add_middleware(
|
63 |
+
CORSMiddleware,
|
64 |
+
allow_origins=origins,
|
65 |
+
allow_credentials=True,
|
66 |
+
allow_methods=["*"], # Allows all methods
|
67 |
+
allow_headers=["*"], # Allows all headers
|
68 |
+
)
|
69 |
+
|
70 |
# --- Modal Distributed Dictionary for Caching ---
|
71 |
video_analysis_cache = modal.Dict.from_name("video_analysis_cache", create_if_missing=True)
|
72 |
|