rogerxavier
commited on
Commit
•
d38fe54
1
Parent(s):
a040df9
Create api.py
Browse files
api.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, File, UploadFile
|
2 |
+
from fastapi.staticfiles import StaticFiles
|
3 |
+
from fastapi.responses import FileResponse
|
4 |
+
from transformers import pipeline,AutoModel
|
5 |
+
import streamlit as st
|
6 |
+
from PIL import Image
|
7 |
+
import torch
|
8 |
+
import numpy as np
|
9 |
+
import urllib.request
|
10 |
+
import io
|
11 |
+
import os
|
12 |
+
|
13 |
+
app = FastAPI()
|
14 |
+
|
15 |
+
@app.get("/inference")
|
16 |
+
def inference():
|
17 |
+
return "<p>Hello, World!</p>"
|
18 |
+
|
19 |
+
@app.get("/infer_t5")
|
20 |
+
def t5(input):
|
21 |
+
|
22 |
+
return {"output": input}
|
23 |
+
|
24 |
+
|
25 |
+
@app.post("/getCoordinates")
|
26 |
+
async def getCoordinates(image: UploadFile = File(...)):
|
27 |
+
img = await image.read()
|
28 |
+
image = Image.open(io.BytesIO(img)).convert("L").convert("RGB")
|
29 |
+
path_to_image = "save.jpg"
|
30 |
+
image.save(path_to_image)
|
31 |
+
return "获取图片保存成功"
|