Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -22,6 +22,7 @@ app.add_middleware(
|
|
22 |
|
23 |
nlp_qa = pipeline("document-question-answering", model="jinhybr/OCR-DocVQA-Donut")
|
24 |
nlp_qa_v2 = pipeline("document-question-answering", model="faisalraza/layoutlm-invoices")
|
|
|
25 |
|
26 |
description = """
|
27 |
## Image-based Document QA
|
@@ -98,6 +99,23 @@ async def perform_document_qa(
|
|
98 |
except Exception as e:
|
99 |
return JSONResponse(content=f"Error processing file: {str(e)}", status_code=500)
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
# Set up CORS middleware
|
102 |
origins = ["*"] # or specify your list of allowed origins
|
103 |
app.add_middleware(
|
|
|
22 |
|
23 |
nlp_qa = pipeline("document-question-answering", model="jinhybr/OCR-DocVQA-Donut")
|
24 |
nlp_qa_v2 = pipeline("document-question-answering", model="faisalraza/layoutlm-invoices")
|
25 |
+
nlp_qa_v3 = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
26 |
|
27 |
description = """
|
28 |
## Image-based Document QA
|
|
|
99 |
except Exception as e:
|
100 |
return JSONResponse(content=f"Error processing file: {str(e)}", status_code=500)
|
101 |
|
102 |
+
@app.post("/uploadfilev3/", description="Upload an image file to extract text and answer provided questions.")
|
103 |
+
async def perform_document_qa(
|
104 |
+
context: str = Form(...),
|
105 |
+
question: str = Form(...),
|
106 |
+
):
|
107 |
+
try:
|
108 |
+
QA_input = {
|
109 |
+
'question': question,
|
110 |
+
'context': context
|
111 |
+
}
|
112 |
+
|
113 |
+
res = nlp(QA_input)
|
114 |
+
|
115 |
+
return res
|
116 |
+
except Exception as e:
|
117 |
+
return JSONResponse(content=f"Error processing file: {str(e)}", status_code=500)
|
118 |
+
|
119 |
# Set up CORS middleware
|
120 |
origins = ["*"] # or specify your list of allowed origins
|
121 |
app.add_middleware(
|