test fast api
Browse files
app.py
CHANGED
|
@@ -17,24 +17,21 @@ import streamlit as st
|
|
| 17 |
|
| 18 |
# pytesseract.pytesseract.tesseract_cmd = r’./Tesseract-OCR/tesseract.exe’
|
| 19 |
choices = os.popen('tesseract --list-langs').read().split('\n')[1:-1]
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
|
| 27 |
# NOTE - we configure docs_url to serve the interactive Docs at the root path
|
| 28 |
# of the app. This way, we can use the docs as a landing page for the app on Spaces.
|
| 29 |
-
|
| 30 |
|
| 31 |
pipe = pipeline("document-question-answering", model="impira/layoutlm-document-qa")
|
| 32 |
-
image = 'https://templates.invoicehome.com/invoice-template-us-neat-750px.png'
|
| 33 |
|
| 34 |
-
question = "What is the invoice number?"
|
| 35 |
-
output = pipe(image, question)
|
| 36 |
|
| 37 |
-
st.write(output)
|
| 38 |
|
| 39 |
# @app.post("/predict")
|
| 40 |
# def predict(image_file: bytes = File(...), question: str = Form(...)):
|
|
@@ -48,6 +45,10 @@ st.write(output)
|
|
| 48 |
# output = pipe(image, question)
|
| 49 |
# return output
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# pytesseract.pytesseract.tesseract_cmd = r’./Tesseract-OCR/tesseract.exe’
|
| 19 |
choices = os.popen('tesseract --list-langs').read().split('\n')[1:-1]
|
| 20 |
+
description = """
|
| 21 |
+
## DocQA with 🤗 transformers, FastAPI, and Docker
|
| 22 |
+
This app shows how to do Document Question Answering using
|
| 23 |
+
FastAPI in a Docker Space 🚀
|
| 24 |
+
Check out the docs for the `/predict` endpoint below to try it out!
|
| 25 |
+
"""
|
| 26 |
|
| 27 |
# NOTE - we configure docs_url to serve the interactive Docs at the root path
|
| 28 |
# of the app. This way, we can use the docs as a landing page for the app on Spaces.
|
| 29 |
+
app = FastAPI(docs_url="/", description=description)
|
| 30 |
|
| 31 |
pipe = pipeline("document-question-answering", model="impira/layoutlm-document-qa")
|
|
|
|
| 32 |
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
#st.write(output)
|
| 35 |
|
| 36 |
# @app.post("/predict")
|
| 37 |
# def predict(image_file: bytes = File(...), question: str = Form(...)):
|
|
|
|
| 45 |
# output = pipe(image, question)
|
| 46 |
# return output
|
| 47 |
|
| 48 |
+
@app.get("/hello")
|
| 49 |
+
def read_root():
|
| 50 |
+
image = 'https://templates.invoicehome.com/invoice-template-us-neat-750px.png'
|
| 51 |
+
|
| 52 |
+
question = "What is the invoice number?"
|
| 53 |
+
output = pipe(image, question)
|
| 54 |
+
return output
|