acharyaaditya26 commited on
Commit
9719116
1 Parent(s): 76d7398

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -2,6 +2,7 @@ from fastapi import FastAPI, File, UploadFile, HTTPException
2
  from fastapi.responses import JSONResponse, HTMLResponse
3
  from fastapi.staticfiles import StaticFiles
4
  from fastapi.templating import Jinja2Templates
 
5
  import fitz # PyMuPDF
6
  from transformers import AutoModel, AutoTokenizer
7
  from PIL import Image
@@ -20,6 +21,15 @@ import uvicorn
20
 
21
  app = FastAPI()
22
 
 
 
 
 
 
 
 
 
 
23
  # Load tokenizer and model
24
  tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
25
  model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, device_map='cuda', use_safetensors=True)
@@ -91,7 +101,7 @@ def cleanup_old_files():
91
  current_time = time.time()
92
  for folder in [UPLOAD_FOLDER, RESULTS_FOLDER]:
93
  for file_path in Path(folder).glob('*'):
94
- if current_time - file_path.stat().st_mtime > 3600: # 1 hour
95
  file_path.unlink()
96
 
97
  cleanup_old_files()
 
2
  from fastapi.responses import JSONResponse, HTMLResponse
3
  from fastapi.staticfiles import StaticFiles
4
  from fastapi.templating import Jinja2Templates
5
+ from fastapi.middleware.cors import CORSMiddleware
6
  import fitz # PyMuPDF
7
  from transformers import AutoModel, AutoTokenizer
8
  from PIL import Image
 
21
 
22
  app = FastAPI()
23
 
24
+ # Add CORS middleware
25
+ app.add_middleware(
26
+ CORSMiddleware,
27
+ allow_origins=["*"], # Allow all origins for simplicity
28
+ allow_credentials=True,
29
+ allow_methods=["*"],
30
+ allow_headers=["*"],
31
+ )
32
+
33
  # Load tokenizer and model
34
  tokenizer = AutoTokenizer.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True)
35
  model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True, device_map='cuda', use_safetensors=True)
 
101
  current_time = time.time()
102
  for folder in [UPLOAD_FOLDER, RESULTS_FOLDER]:
103
  for file_path in Path(folder).glob('*'):
104
+ if current_time - file_path.stat().st_mtime > 3600: # 1 hour
105
  file_path.unlink()
106
 
107
  cleanup_old_files()