-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel-api.py
More file actions
28 lines (22 loc) · 831 Bytes
/
model-api.py
File metadata and controls
28 lines (22 loc) · 831 Bytes
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
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse
from subprocess import check_output
from predict_words import perform_ocr
from typing import Optional
app = FastAPI()
@app.get("/predict_sentnece/")
async def run_script() -> str:
try:
# Run the provided script using check_output
return perform_ocr()
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.get("/")
async def read_root():
return {"message": "Welcome! Use the /run_script/ endpoint to execute a script."}
@app.get("/docs", include_in_schema=False)
async def custom_swagger_ui_html():
return get_swagger_ui_html(openapi_url="/openapi.json", title="Image API")
# if __name__ == "__main__":
# import uvicorn
# uvicorn.run(app, host="0.0.0.0", port=8010)