yoniyoni12 commited on
Commit
ccc0e18
·
verified ·
1 Parent(s): c882487

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, File, UploadFile
2
+ import shutil
3
+ import os
4
+ from OCR import pipeline
5
+
6
+ app = FastAPI()
7
+
8
+ UPLOAD_FOLDER = "temp"
9
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
10
+
11
+ @app.post("/predict")
12
+ async def predict(file: UploadFile = File(...)):
13
+ file_path = os.path.join(UPLOAD_FOLDER, file.filename)
14
+
15
+ with open(file_path, "wb") as buffer:
16
+ shutil.copyfileobj(file.file, buffer)
17
+
18
+ try:
19
+ text = pipeline(file_path, bw=True)
20
+ except Exception as e:
21
+ return {"error": str(e)}
22
+
23
+ return {"text": text}