LapStore commited on
Commit
473fa66
·
1 Parent(s): 0c38a00

modified back mGE STEP 1

Browse files
Files changed (3) hide show
  1. app.py +13 -4
  2. index.html +5 -3
  3. server.py +3 -0
app.py CHANGED
@@ -9,6 +9,7 @@ import numpy as np
9
  import ast
10
  from server import *
11
  import cv2
 
12
 
13
  #http://localhost:8000
14
  app = FastAPI()
@@ -22,11 +23,19 @@ def main():
22
 
23
 
24
  @app.post('/imageStep1')
25
- async def image_step1(image_file: UploadFile = File(...),type_of_filters: str = Form(...), blur_radius: str = Form(...)):#--->,background_image: UploadFile = File(...)):
26
-
27
- contents = await image_file.read()
28
- image = Image.open(io.BytesIO(contents))
 
 
 
 
 
 
 
29
 
 
30
  produced_image=SegmenterBackground().Back_step1(image,type_of_filters,int(blur_radius))[0]#---->
31
 
32
  # Save the processed image to a temporary file
 
9
  import ast
10
  from server import *
11
  import cv2
12
+ from typing import Optional
13
 
14
  #http://localhost:8000
15
  app = FastAPI()
 
23
 
24
 
25
  @app.post('/imageStep1')
26
+ async def image_step1(image_file: UploadFile = File(...),background_image: Optional [UploadFile] = File(None),type_of_filters: str = Form(...), blur_radius: str = Form(...)):#--->,background_image: UploadFile = File(...)):
27
+
28
+ input_to_type_of_filters=None
29
+ if background_image:
30
+ # Process the image if provided
31
+ return {"filename": background_image.filename}
32
+ else:
33
+ # Handle the case where no image is provided
34
+ return {"message": "No image provided"}
35
+ contents_img = await image_file.read()
36
+ image = Image.open(io.BytesIO(contents_img))
37
 
38
+
39
  produced_image=SegmenterBackground().Back_step1(image,type_of_filters,int(blur_radius))[0]#---->
40
 
41
  # Save the processed image to a temporary file
index.html CHANGED
@@ -2,11 +2,13 @@
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
- Name :<p><input type="text" name="kind_back" /></p><br>
8
  blur_radius :<p><input type="text" name="blur_radius" /></p><br>
9
- Video : <input type="file" name="video_file" required><br><br>
 
 
10
  <p><input type="submit" value="submit" /></p>
11
  </form>
12
  </center>
 
2
  <body bgcolor="#00cccc">
3
  <center>
4
  <br><br><br>
5
+ <form action="https://taha454-backg.hf.space/imageStep1" 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
  blur_radius :<p><input type="text" name="blur_radius" /></p><br>
9
+ Image : <input type="file" name="image_file" required><br><br>
10
+ Background_Image : <input type="file" name="background_image" required><br><br>
11
+
12
  <p><input type="submit" value="submit" /></p>
13
  </form>
14
  </center>
server.py CHANGED
@@ -10,6 +10,9 @@ import matplotlib.pyplot as plt
10
 
11
  warnings.filterwarnings("ignore", category=FutureWarning)
12
 
 
 
 
13
  class SegmenterBackground():
14
  def __init__(self) -> None:
15
  self.segment_names = {} # This dictionary will store names for segments across multiple inferences
 
10
 
11
  warnings.filterwarnings("ignore", category=FutureWarning)
12
 
13
+ ## use class to make each time inference not conflic with other object
14
+
15
+
16
  class SegmenterBackground():
17
  def __init__(self) -> None:
18
  self.segment_names = {} # This dictionary will store names for segments across multiple inferences