uzi007 commited on
Commit
e074083
1 Parent(s): d2ff2ae

Added CORS Handling

Browse files
Files changed (1) hide show
  1. main.py +22 -0
main.py CHANGED
@@ -2,18 +2,40 @@ import pytorch_test
2
 
3
  import uvicorn
4
  from fastapi import FastAPI, Request
 
5
 
6
  from media_download import YoutubeDownloader
7
  from transcription import StableWhisper
8
  from summarizer import Extract_Summary, AudioBookNarration
9
  from audiobook import AudioBook
10
 
 
 
 
11
  app = FastAPI()
 
 
12
  output_folder = 'Output'
13
 
14
  # Create a context variable to store the contexts for each user
15
  users_context = dict()
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  @app.get("/get_media_info")
19
  async def get_media_info(request: Request, url: str):
 
2
 
3
  import uvicorn
4
  from fastapi import FastAPI, Request
5
+ from fastapi.middleware.cors import CORSMiddleware
6
 
7
  from media_download import YoutubeDownloader
8
  from transcription import StableWhisper
9
  from summarizer import Extract_Summary, AudioBookNarration
10
  from audiobook import AudioBook
11
 
12
+
13
+ ### API Configurations
14
+
15
  app = FastAPI()
16
+
17
+ # Output Directory for Files Storage
18
  output_folder = 'Output'
19
 
20
  # Create a context variable to store the contexts for each user
21
  users_context = dict()
22
 
23
+ # CORS (Cross-Origin Resource Sharing)
24
+ origins = [
25
+ "http://localhost",
26
+ "http://localhost:4200",
27
+ ]
28
+
29
+ app.add_middleware(
30
+ CORSMiddleware,
31
+ allow_origins=origins,
32
+ allow_credentials=True,
33
+ allow_methods=["*"],
34
+ allow_headers=["*"],
35
+ )
36
+
37
+
38
+ ### APIs
39
 
40
  @app.get("/get_media_info")
41
  async def get_media_info(request: Request, url: str):