Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -23,6 +23,7 @@ app.add_middleware(
|
|
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
|
@@ -116,6 +117,18 @@ async def perform_document_qa(
|
|
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(
|
|
|
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 |
+
nlp_classification = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
|
27 |
|
28 |
description = """
|
29 |
## Image-based Document QA
|
|
|
117 |
except Exception as e:
|
118 |
return JSONResponse(content=f"Error processing file: {str(e)}", status_code=500)
|
119 |
|
120 |
+
@app.post("/classify/", description="Classify the provided text.")
|
121 |
+
async def classify_text(text: str = Form(...)):
|
122 |
+
try:
|
123 |
+
# Perform text classification using the pipeline
|
124 |
+
result = nlp_classification(text)
|
125 |
+
|
126 |
+
# Return the classification result
|
127 |
+
return result
|
128 |
+
except Exception as e:
|
129 |
+
return JSONResponse(content=f"Error classifying text: {str(e)}", status_code=500)
|
130 |
+
|
131 |
+
|
132 |
# Set up CORS middleware
|
133 |
origins = ["*"] # or specify your list of allowed origins
|
134 |
app.add_middleware(
|