LapStore
commited on
Commit
•
9beab52
1
Parent(s):
8791de8
modified video fast api
Browse files- app.py +30 -9
- index.html +16 -3
app.py
CHANGED
@@ -65,13 +65,11 @@ async def image_step1(image_file: UploadFile = File(...),background_image: Optio
|
|
65 |
@app.post('/imageStep2')
|
66 |
async def image_step2(image_file: UploadFile = File(...),background_image: Optional [UploadFile] = File(None),type_of_filters: str = Form(...),
|
67 |
things_replace: str = Form(...), blur_radius: str = Form(...)):#--->,background_image: UploadFile = File(...)):
|
68 |
-
|
69 |
-
contents = await image_file.read()
|
70 |
-
image = Image.open(io.BytesIO(contents))
|
71 |
-
|
72 |
things_replace=ast.literal_eval(things_replace)
|
73 |
blur_radius=int(blur_radius)
|
74 |
|
|
|
75 |
input_to_type_of_filters=None
|
76 |
|
77 |
if background_image and background_image.filename:
|
@@ -82,6 +80,10 @@ async def image_step2(image_file: UploadFile = File(...),background_image: Optio
|
|
82 |
input_to_type_of_filters = type_of_filters
|
83 |
|
84 |
|
|
|
|
|
|
|
|
|
85 |
produced_image=SegmenterBackground().Back_step2(image,input_to_type_of_filters,things_replace,int(blur_radius))
|
86 |
|
87 |
# Save the processed image to a temporary file
|
@@ -92,18 +94,37 @@ async def image_step2(image_file: UploadFile = File(...),background_image: Optio
|
|
92 |
return FileResponse(output_file_path_tmp, media_type='image/png', filename="/tmp/tmp_processed_image.png")
|
93 |
|
94 |
|
|
|
|
|
95 |
@app.post('/Video')
|
96 |
-
async def Video(video_file: UploadFile = File(...),
|
|
|
|
|
97 |
#video_data = await video_file.read()
|
98 |
#nparr = np.frombuffer(video_data, np.uint8)
|
99 |
#video_path=cv2.imdecode(nparr, cv2.IMREAD_COLOR) #named this as just passed as it's path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
-
|
102 |
-
|
|
|
103 |
f.write(await video_file.read())
|
104 |
|
105 |
-
|
|
|
|
|
106 |
|
107 |
-
return StreamingResponse(open(
|
108 |
|
109 |
|
|
|
65 |
@app.post('/imageStep2')
|
66 |
async def image_step2(image_file: UploadFile = File(...),background_image: Optional [UploadFile] = File(None),type_of_filters: str = Form(...),
|
67 |
things_replace: str = Form(...), blur_radius: str = Form(...)):#--->,background_image: UploadFile = File(...)):
|
68 |
+
|
|
|
|
|
|
|
69 |
things_replace=ast.literal_eval(things_replace)
|
70 |
blur_radius=int(blur_radius)
|
71 |
|
72 |
+
|
73 |
input_to_type_of_filters=None
|
74 |
|
75 |
if background_image and background_image.filename:
|
|
|
80 |
input_to_type_of_filters = type_of_filters
|
81 |
|
82 |
|
83 |
+
contents = await image_file.read()
|
84 |
+
image = Image.open(io.BytesIO(contents))
|
85 |
+
|
86 |
+
|
87 |
produced_image=SegmenterBackground().Back_step2(image,input_to_type_of_filters,things_replace,int(blur_radius))
|
88 |
|
89 |
# Save the processed image to a temporary file
|
|
|
94 |
return FileResponse(output_file_path_tmp, media_type='image/png', filename="/tmp/tmp_processed_image.png")
|
95 |
|
96 |
|
97 |
+
|
98 |
+
|
99 |
@app.post('/Video')
|
100 |
+
async def Video(video_file: UploadFile = File(...),background_image: Optional [UploadFile] = File(None),kind_back: str = Form(...)
|
101 |
+
,type_of_filters: str = Form(...),blur_radius: str = Form(...)):#--->,background_image: UploadFile = File(...)):
|
102 |
+
|
103 |
#video_data = await video_file.read()
|
104 |
#nparr = np.frombuffer(video_data, np.uint8)
|
105 |
#video_path=cv2.imdecode(nparr, cv2.IMREAD_COLOR) #named this as just passed as it's path
|
106 |
+
blur_radius=int(blur_radius)
|
107 |
+
kind_back=ast.literal_eval(kind_back)
|
108 |
+
|
109 |
+
input_to_type_of_filters=None
|
110 |
+
|
111 |
+
if background_image and background_image.filename:
|
112 |
+
contents__back = await background_image.read()
|
113 |
+
image_back = Image.open(io.BytesIO(contents__back))
|
114 |
+
input_to_type_of_filters = image_back
|
115 |
+
else:
|
116 |
+
input_to_type_of_filters = type_of_filters
|
117 |
+
|
118 |
|
119 |
+
input_path_toWrite = f'/tmp/tmp_imput.avi'#{video_file.filename}
|
120 |
+
output_path = '/tmp/tmp_output.avi'
|
121 |
+
with open(input_path_toWrite, 'wb') as f:
|
122 |
f.write(await video_file.read())
|
123 |
|
124 |
+
#--------> mp4?
|
125 |
+
|
126 |
+
SegmenterBackground().Back_video(input_path_toWrite, output_path,input_to_type_of_filters,kind_back,blur_radius)#video,background_image,what_remove,blur_radius=23)
|
127 |
|
128 |
+
return StreamingResponse(open(output_path, "rb"), media_type="video/avi")
|
129 |
|
130 |
|
index.html
CHANGED
@@ -2,12 +2,12 @@
|
|
2 |
<body bgcolor="#00cccc">
|
3 |
<center>
|
4 |
<br><br><br>
|
5 |
-
<form action="https://taha454-backg.hf.space/
|
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 |
-
|
11 |
Background_Image : <input type="file" name="background_image" ><br><br>
|
12 |
|
13 |
<p><input type="submit" value="submit" /></p>
|
@@ -15,3 +15,16 @@
|
|
15 |
</center>
|
16 |
</body>
|
17 |
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
<body bgcolor="#00cccc">
|
3 |
<center>
|
4 |
<br><br><br>
|
5 |
+
<form action="https://taha454-backg.hf.space/Video" method="post" enctype="multipart/form-data">
|
6 |
<p><h3>Enter Image:</h3></p>
|
7 |
type_of_filters :<p><input type="text" name="type_of_filters" /></p><br>
|
8 |
+
kind_back :<p><input type="text" name="kind_back" /></p><br>
|
9 |
blur_radius :<p><input type="text" name="blur_radius" /></p><br>
|
10 |
+
Video : <input type="file" name="image_file" required><br><br>
|
11 |
Background_Image : <input type="file" name="background_image" ><br><br>
|
12 |
|
13 |
<p><input type="submit" value="submit" /></p>
|
|
|
15 |
</center>
|
16 |
</body>
|
17 |
</html>
|
18 |
+
|
19 |
+
<!--
|
20 |
+
<form action="https://taha454-backg.hf.space/imageStep2" method="post" enctype="multipart/form-data">
|
21 |
+
<p><h3>Enter Image:</h3></p>
|
22 |
+
type_of_filters :<p><input type="text" name="type_of_filters" /></p><br>
|
23 |
+
things_replace :<p><input type="text" name="things_replace" /></p><br>
|
24 |
+
blur_radius :<p><input type="text" name="blur_radius" /></p><br>
|
25 |
+
Image : <input type="file" name="image_file" required><br><br>
|
26 |
+
Background_Image : <input type="file" name="background_image" ><br><br>
|
27 |
+
|
28 |
+
<p><input type="submit" value="submit" /></p>
|
29 |
+
</form>
|
30 |
+
-->
|