Spaces:
Runtime error
Runtime error
| # main.py | |
| from fastapi import FastAPI | |
| from PIL import Image | |
| import base64 | |
| from fastapi.responses import HTMLResponse, FileResponse | |
| app = FastAPI() | |
| async def root(): | |
| return FileResponse(path="static/index.html", media_type="text/html") | |
| async def root(): | |
| """Basic HTML response.""" | |
| body = ( | |
| "<html>" | |
| "<body style='padding: 10px;'>" | |
| "<h1>Welcome to the API</h1>" | |
| "<div>" | |
| "Check the docs: <a href='/docs'>here</a>" | |
| "</div>" | |
| "</body>" | |
| "</html>" | |
| ) | |
| return HTMLResponse(content=body) | |
| async def cal_api(): | |
| images = [] | |
| with open('workdir/lion.jpg', 'rb') as open_file: | |
| byte_content = open_file.read() | |
| base64_bytes = base64.b64encode(byte_content) | |
| base64_string = base64_bytes.decode('utf-8') | |
| images.append(base64_string) | |
| with open('workdir/cheetah.jpg', 'rb') as open_file: | |
| byte_content = open_file.read() | |
| base64_bytes = base64.b64encode(byte_content) | |
| base64_string = base64_bytes.decode('utf-8') | |
| images.append(base64_string) | |
| #image_path='lion.jpg' | |
| #pilim = Image.open(image_path) | |
| #pilimrot = pilim.rotate(45) | |
| return {"data": images} | |
| async def read_item(item_id): | |
| return {"item_id": item_id} | |