| from fastapi import FastAPI
|
| from fastapi.responses import FileResponse
|
| import os
|
| import uvicorn
|
|
|
| app = FastAPI()
|
|
|
| image_directory='./images'
|
| if not os.path.exists(image_directory):
|
| os.makedirs(image_directory)
|
|
|
| @app.get("/images/{image_name}")
|
| async def get_image(image_name: str):
|
| image_path = os.path.join(image_directory, image_name)
|
|
|
| if os.path.exists(image_path):
|
| return FileResponse(image_path)
|
| else:
|
| return {"error": "Image not found"}
|
|
|
| if __name__ == "__main__":
|
| uvicorn.run(app, host="127.0.0.1", port=5000)
|
|
|
|
|