Spaces:
				
			
			
	
			
			
		Paused
		
	
	
	
			
			
	
	
	
	
		
		
		Paused
		
	Update app/main.py
Browse files- app/main.py +26 -18
    	
        app/main.py
    CHANGED
    
    | @@ -1,18 +1,26 @@ | |
| 1 | 
            -
            from fastapi import FastAPI
         | 
| 2 | 
            -
            from fastapi.middleware.cors import CORSMiddleware
         | 
| 3 | 
            -
            from app.api import ask, rewrite, home
         | 
| 4 | 
            -
             | 
| 5 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
            app. | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 1 | 
            +
            from fastapi import FastAPI
         | 
| 2 | 
            +
            from fastapi.middleware.cors import CORSMiddleware
         | 
| 3 | 
            +
            from app.api import ask, rewrite, home
         | 
| 4 | 
            +
            import os
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            os.environ["HF_HOME"] = "./cache"
         | 
| 7 | 
            +
            os.environ["TRANSFORMERS_CACHE"] = "./cache"
         | 
| 8 | 
            +
            os.environ["TORCH_HOME"] = "./cache"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # Tạo folder cache nếu chưa tồn tại
         | 
| 11 | 
            +
            os.makedirs("./cache", exist_ok=True)
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            app = FastAPI()
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            # Add CORS middleware
         | 
| 16 | 
            +
            app.add_middleware(
         | 
| 17 | 
            +
                CORSMiddleware,
         | 
| 18 | 
            +
                allow_origins=["*"],  # Allows all origins
         | 
| 19 | 
            +
                allow_credentials=True,
         | 
| 20 | 
            +
                allow_methods=["*"],  # Allows all methods
         | 
| 21 | 
            +
                allow_headers=["*"],  # Allows all headers
         | 
| 22 | 
            +
            )
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            app.include_router(ask.router)
         | 
| 25 | 
            +
            app.include_router(rewrite.router)
         | 
| 26 | 
            +
            app.include_router(home.router)
         | 
