AkashKumarave commited on
Commit
30ea5f3
·
verified ·
1 Parent(s): b6dcd96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -11,18 +11,23 @@ app = FastAPI()
11
  # Add CORS middleware
12
  app.add_middleware(
13
  CORSMiddleware,
14
- allow_origins=["*"], # Adjust for production
15
  allow_credentials=True,
16
  allow_methods=["*"],
17
  allow_headers=["*"],
18
  )
19
 
 
 
 
 
 
20
  @app.post("/api/convert")
21
  async def convert_pdf(file: bytes = File(...)):
22
  try:
23
  # Parse PDF with pdfplumber
24
  with pdfplumber.open(BytesIO(file)) as pdf:
25
- page = pdf.pages[0] # First page for simplicity
26
  width, height = page.width, page.height
27
 
28
  # Initialize result
@@ -43,7 +48,7 @@ async def convert_pdf(file: bytes = File(...)):
43
  "font_family": char["fontname"].split("+")[-1] or "Arial",
44
  "font_style": "Regular",
45
  "font_size": char["size"],
46
- "color": {"r": 0, "g": 0, "b": 0} # Simplified: enhance for color extraction
47
  })
48
 
49
  # Extract images
 
11
  # Add CORS middleware
12
  app.add_middleware(
13
  CORSMiddleware,
14
+ allow_origins=["*"], # Restrict in production
15
  allow_credentials=True,
16
  allow_methods=["*"],
17
  allow_headers=["*"],
18
  )
19
 
20
+ # Root route to avoid 404 errors
21
+ @app.get("/")
22
+ async def root():
23
+ return {"message": "PDF to Figma API"}
24
+
25
  @app.post("/api/convert")
26
  async def convert_pdf(file: bytes = File(...)):
27
  try:
28
  # Parse PDF with pdfplumber
29
  with pdfplumber.open(BytesIO(file)) as pdf:
30
+ page = pdf.pages[0] # First page
31
  width, height = page.width, page.height
32
 
33
  # Initialize result
 
48
  "font_family": char["fontname"].split("+")[-1] or "Arial",
49
  "font_style": "Regular",
50
  "font_size": char["size"],
51
+ "color": {"r": 0, "g": 0, "b": 0}
52
  })
53
 
54
  # Extract images