from fastapi import FastAPI, File, UploadFile from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse from PIL import Image import numpy as np import urllib.request import io import os from moviepyTest import test from typing import * app = FastAPI() @app.get("/inference") def inference(): return "
Hello, World!
" @app.get("/infer_t5") def t5(input): return {"output": input} @app.get("/moviepyTest") def t5(): result = test() return {"output": result} @app.post("/getOriginalMangaList") async def getOriginalMangaList(images: List[UploadFile] = File(...)): for idx, image in enumerate(images): img = await image.read() image = Image.open(io.BytesIO(img)).convert("L").convert("RGB") path_to_image = f"/manga/{idx}.jpg" image.save(path_to_image) return "获取图片保存成功" @app.delete("/deleteAllMangaFiles") async def delete_all_manga_files(): directory = "manga" for filename in os.listdir(directory): file_path = os.path.join(directory, filename) if os.path.isfile(file_path): os.remove(file_path) return {"message": "成功删除manga目录下的所有文件"}