Update handler.py
Browse files- handler.py +16 -1
handler.py
CHANGED
|
@@ -3,6 +3,10 @@ from PIL import Image
|
|
| 3 |
import io
|
| 4 |
import base64
|
| 5 |
from transformers import GlmOcrProcessor, GlmOcrForConditionalGeneration
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
class EndpointHandler():
|
| 8 |
def __init__(self, path=""):
|
|
@@ -33,4 +37,15 @@ class EndpointHandler():
|
|
| 33 |
# Decode results
|
| 34 |
result = self.processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 35 |
|
| 36 |
-
return [{"generated_text": result}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import io
|
| 4 |
import base64
|
| 5 |
from transformers import GlmOcrProcessor, GlmOcrForConditionalGeneration
|
| 6 |
+
from fastapi import FastAPI, Request
|
| 7 |
+
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
handler = EndpointHandler("/repository")
|
| 10 |
|
| 11 |
class EndpointHandler():
|
| 12 |
def __init__(self, path=""):
|
|
|
|
| 37 |
# Decode results
|
| 38 |
result = self.processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 39 |
|
| 40 |
+
return [{"generated_text": result}]
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
@app.post("/")
|
| 44 |
+
@app.post("/v1/chat/completions")
|
| 45 |
+
async def handle(request: Request):
|
| 46 |
+
data = await request.json()
|
| 47 |
+
return handler(data)
|
| 48 |
+
|
| 49 |
+
@app.get("/health")
|
| 50 |
+
async def health():
|
| 51 |
+
return {"status": "ok"}
|