File size: 738 Bytes
3c97fa1
a1be15a
 
 
3c97fa1
 
 
a1be15a
3e805bb
 
 
 
 
 
 
 
a1be15a
 
 
 
 
ca3731f
 
 
3e805bb
5a9777a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
from transformers import pipeline

app = FastAPI()


from transformers import pipeline

image_to_text = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")


# [{'generated_text': 'a soccer game with a player jumping to catch the ball '}]

model = AutoModelForSeq2SeqLM.from_pretrained("google/pix2struct-ocrvqa-large")
app.mount("/", StaticFiles(directory="static", html=True), name="static")

@app.get("/")
def index() -> FileResponse:
    return FileResponse(path="/app/static/index.html", media_type="text/html")

@app.get("/ocr")
def ocr(input):
    result = image_to_text(input)
    print(result)