Spaces:
Runtime error
Runtime error
fix: output not shown for all input docs
Browse files- main.py +27 -14
- requirements.txt +1 -0
main.py
CHANGED
|
@@ -23,16 +23,17 @@ def t5(input):
|
|
| 23 |
|
| 24 |
@app.post("/classify")
|
| 25 |
async def classify_doc(files: List[UploadFile] = File(...)):
|
| 26 |
-
for file in files:
|
| 27 |
-
try:
|
| 28 |
-
contents = file.file.read()
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
|
@@ -42,6 +43,19 @@ def index() -> FileResponse:
|
|
| 42 |
return FileResponse(path="/app/static/index.html", media_type="text/html")
|
| 43 |
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
import re
|
|
@@ -146,10 +160,9 @@ import os
|
|
| 146 |
import requests
|
| 147 |
from io import BytesIO
|
| 148 |
|
| 149 |
-
def classify_acct_dtype_str(
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
dtype_inf, dtype_conf = doctype_classify(ipt, "city-streets.jpg")
|
| 153 |
|
| 154 |
return dtype_inf
|
| 155 |
|
|
|
|
| 23 |
|
| 24 |
@app.post("/classify")
|
| 25 |
async def classify_doc(files: List[UploadFile] = File(...)):
|
| 26 |
+
# for file in files:
|
| 27 |
+
# try:
|
| 28 |
+
# contents = file.file.read()
|
| 29 |
+
# filename = file.filename
|
| 30 |
+
# classify_res = classify_acct_dtype_str(contents, filename)
|
| 31 |
+
# except Exception as err:
|
| 32 |
+
# print(Exception, err)
|
| 33 |
+
# return {"message": "There was an error in uploading file(s)"}
|
| 34 |
+
# finally:
|
| 35 |
+
# file.file.close()
|
| 36 |
+
return {"message": f"{[file.filename for file in files]} : {[getDocClassType(file) for file in files]}"}
|
| 37 |
|
| 38 |
|
| 39 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
|
|
|
| 43 |
return FileResponse(path="/app/static/index.html", media_type="text/html")
|
| 44 |
|
| 45 |
|
| 46 |
+
def getDocClassType(file):
|
| 47 |
+
classify_res = ""
|
| 48 |
+
try:
|
| 49 |
+
contents = file.file.read()
|
| 50 |
+
filename = file.filename
|
| 51 |
+
classify_res = classify_acct_dtype_str(contents, filename)
|
| 52 |
+
except Exception as err:
|
| 53 |
+
print(Exception, err)
|
| 54 |
+
return {"Error in reading file."}
|
| 55 |
+
finally:
|
| 56 |
+
file.file.close()
|
| 57 |
+
|
| 58 |
+
return classify_res
|
| 59 |
|
| 60 |
|
| 61 |
import re
|
|
|
|
| 160 |
import requests
|
| 161 |
from io import BytesIO
|
| 162 |
|
| 163 |
+
def classify_acct_dtype_str(content, filename):
|
| 164 |
+
ipt = Image.open(BytesIO(content))
|
| 165 |
+
dtype_inf, dtype_conf = doctype_classify(ipt, filename)
|
|
|
|
| 166 |
|
| 167 |
return dtype_inf
|
| 168 |
|
requirements.txt
CHANGED
|
@@ -2,6 +2,7 @@ fastapi
|
|
| 2 |
python-multipart
|
| 3 |
typing
|
| 4 |
uvicorn[standard]
|
|
|
|
| 5 |
aiohttp==3.9.1
|
| 6 |
aiosignal==1.3.1
|
| 7 |
altgraph==0.17.4
|
|
|
|
| 2 |
python-multipart
|
| 3 |
typing
|
| 4 |
uvicorn[standard]
|
| 5 |
+
pdf2image==1.16.3
|
| 6 |
aiohttp==3.9.1
|
| 7 |
aiosignal==1.3.1
|
| 8 |
altgraph==0.17.4
|