File size: 833 Bytes
2490aa1
 
 
 
 
 
 
 
 
 
 
abf0b62
2490aa1
 
 
 
 
5050dd6
 
2490aa1
 
 
 
 
 
 
 
abf0b62
2490aa1
 
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
28
29
30
from fastapi import FastAPI, File, UploadFile
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
from transformers import pipeline,AutoModel
import streamlit as st
from PIL import Image
import torch
import numpy as np
import urllib.request
import io
import os
from ofa_ocr import ofa_ocr_gr ##导入ofa_ocr中的大函数,方便使用其获取坐标的子函数

app = FastAPI()

@app.get("/infer_t5")
def t5(input):
    
    return {"output": input}

    
@app.post("/getCoordinates")
async def getCoordinates(image: UploadFile = File(...)):
    img = await image.read()
    image = Image.open(io.BytesIO(img)).convert("L").convert("RGB")
    path_to_image = "save.jpg"
    image.save(path_to_image)
    result = ofa_ocr_gr.ocr_api(path_to_image)[2]
    os.remove(path_to_image)
    return result