refoundd commited on
Commit
992d42e
·
verified ·
1 Parent(s): 2ede802

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.responses import FileResponse
3
+ import os
4
+ import uvicorn
5
+
6
+ app = FastAPI()
7
+
8
+ image_directory='./images'
9
+ if not os.path.exists(image_directory):
10
+ os.makedirs(image_directory)
11
+
12
+ @app.get("/images/{image_name}")
13
+ async def get_image(image_name: str):
14
+ image_path = os.path.join(image_directory, image_name)
15
+
16
+ if os.path.exists(image_path):
17
+ return FileResponse(image_path)
18
+ else:
19
+ return {"error": "Image not found"}
20
+
21
+ if __name__ == "__main__":
22
+ uvicorn.run(app, host="127.0.0.1", port=5000)
23
+