LapStore commited on
Commit ·
a82c1e0
1
Parent(s): 4d35f36
added limit property but not applied
Browse files- __pycache__/app.cpython-311.pyc +0 -0
- __pycache__/server.cpython-311.pyc +0 -0
- app.py +28 -0
- index.html +2 -7
- requirements.txt +1 -2
__pycache__/app.cpython-311.pyc
ADDED
|
Binary file (7.86 kB). View file
|
|
|
__pycache__/server.cpython-311.pyc
ADDED
|
Binary file (12 kB). View file
|
|
|
app.py
CHANGED
|
@@ -11,16 +11,41 @@ from server import *
|
|
| 11 |
import cv2
|
| 12 |
from typing import Optional
|
| 13 |
import base64
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
#http://localhost:8000
|
| 17 |
app = FastAPI()
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# Root route
|
| 20 |
@app.get('/')
|
| 21 |
def main():
|
| 22 |
return "Hello From Background remover !"
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
@app.post('/imageStep1')
|
|
@@ -128,3 +153,6 @@ async def Video(video_file: UploadFile = File(...),background_image: Optional [U
|
|
| 128 |
return StreamingResponse(open(output_path, "rb"), media_type="video/avi")
|
| 129 |
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
import cv2
|
| 12 |
from typing import Optional
|
| 13 |
import base64
|
| 14 |
+
from fastapi import FastAPI, Request
|
| 15 |
+
from slowapi import Limiter
|
| 16 |
+
from slowapi.util import get_remote_address
|
| 17 |
+
from fastapi.responses import JSONResponse
|
| 18 |
|
| 19 |
|
| 20 |
#http://localhost:8000
|
| 21 |
app = FastAPI()
|
| 22 |
|
| 23 |
+
limiter = Limiter(key_func=get_remote_address)
|
| 24 |
+
app.state.limiter = limiter
|
| 25 |
+
# Register the Limiter with FastAPI
|
| 26 |
+
@app.middleware("http")
|
| 27 |
+
async def add_process_time_header(request: Request, call_next):
|
| 28 |
+
response = await call_next(request)
|
| 29 |
+
return response
|
| 30 |
+
|
| 31 |
+
@app.exception_handler(429)
|
| 32 |
+
async def rate_limit_exceeded(request: Request, exc):
|
| 33 |
+
return JSONResponse(
|
| 34 |
+
status_code=429,
|
| 35 |
+
content={"detail": "Too Many Requests ,please just try 3 times per hour"},
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
# Root route
|
| 41 |
@app.get('/')
|
| 42 |
def main():
|
| 43 |
return "Hello From Background remover !"
|
| 44 |
|
| 45 |
+
@app.post("/items")
|
| 46 |
+
@limiter.limit("3/hour") # must have parameter request
|
| 47 |
+
async def read_items(request: Request, type_of_filters: str = Form(...)):
|
| 48 |
+
return {"items": str(type_of_filters)}
|
| 49 |
|
| 50 |
|
| 51 |
@app.post('/imageStep1')
|
|
|
|
| 153 |
return StreamingResponse(open(output_path, "rb"), media_type="video/avi")
|
| 154 |
|
| 155 |
|
| 156 |
+
if __name__ == "__main__":
|
| 157 |
+
import uvicorn
|
| 158 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
index.html
CHANGED
|
@@ -2,15 +2,10 @@
|
|
| 2 |
<body bgcolor="#00cccc">
|
| 3 |
<center>
|
| 4 |
<br><br><br>
|
| 5 |
-
<form action="
|
| 6 |
<p><h3>Enter Image:</h3></p>
|
| 7 |
type_of_filters :<p><input type="text" name="type_of_filters" /></p><br>
|
| 8 |
-
|
| 9 |
-
blur_radius :<p><input type="text" name="blur_radius" /></p><br>
|
| 10 |
-
Video : <input type="file" name="video_file" required><br><br>
|
| 11 |
-
Background_Image : <input type="file" name="background_image" ><br><br>
|
| 12 |
-
|
| 13 |
-
<p><input type="submit" value="submit" /></p>
|
| 14 |
</form>
|
| 15 |
</center>
|
| 16 |
</body>
|
|
|
|
| 2 |
<body bgcolor="#00cccc">
|
| 3 |
<center>
|
| 4 |
<br><br><br>
|
| 5 |
+
<form action="http://localhost:8000/items" method="post">
|
| 6 |
<p><h3>Enter Image:</h3></p>
|
| 7 |
type_of_filters :<p><input type="text" name="type_of_filters" /></p><br>
|
| 8 |
+
<p><input type="submit" value="submit" /></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
</form>
|
| 10 |
</center>
|
| 11 |
</body>
|
requirements.txt
CHANGED
|
@@ -7,5 +7,4 @@ numpy
|
|
| 7 |
python-multipart
|
| 8 |
ultralytics
|
| 9 |
opencv-python
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 7 |
python-multipart
|
| 8 |
ultralytics
|
| 9 |
opencv-python
|
| 10 |
+
slowapi
|
|
|