LapStore commited on
Commit
4722fbd
1 Parent(s): 6e57d33
Files changed (2) hide show
  1. app.py +23 -33
  2. index.html +4 -4
app.py CHANGED
@@ -8,7 +8,7 @@ from PIL import ImageOps,Image ,ImageFilter
8
  import matplotlib.pyplot as plt
9
  import numpy as np
10
  import ast
11
- import server
12
 
13
  #http://localhost:8000
14
  app = FastAPI()
@@ -18,6 +18,28 @@ app = FastAPI()
18
  def main():
19
  return "Hello World taha"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  @app.post('/predict')
23
  async def predict(supported_types_str: str = Form(),age: str = Form() , file: UploadFile = File(...)):
@@ -38,35 +60,3 @@ async def predict(supported_types_str: str = Form(),age: str = Form() , file: U
38
  # Return the processed image for download
39
  return FileResponse(output_file_path, media_type='image/png', filename="/tmp/tmp_processed_image.png")
40
 
41
-
42
-
43
-
44
-
45
- @app.post('/predict2')
46
- async def predict2(supported_types_str: str = Form(...), age: str = Form(...), file: UploadFile = File(...)):
47
-
48
- contents = await file.read()
49
- image = Image.open(io.BytesIO(contents))
50
-
51
- # Process the image (example: convert to grayscale)
52
- processed_image = image.convert("L")
53
-
54
- # Save the processed image to a BytesIO object
55
- img_byte_arr = io.BytesIO()
56
- processed_image.save(img_byte_arr, format='PNG')
57
- img_byte_arr.seek(0) # Move to the beginning of the BytesIO buffer
58
-
59
- # Create an HTML response with the processed image
60
- html_content = f"""
61
- <html>
62
- <body>
63
- <h3>Processed Image:</h3>
64
- <img src="data:image/png;base64,{img_byte_arr.getvalue().decode('latin1')}" alt="Processed Image" style="max-width: 500px;"/>
65
- <br><br>
66
- <p>Your name: {supported_types_str}</p>
67
- <p>Your age: {age}</p>
68
- <p><a href="/download">Download Processed Image</a></p>
69
- </body>
70
- </html>
71
- """
72
- return HTMLResponse(content=html_content)
 
8
  import matplotlib.pyplot as plt
9
  import numpy as np
10
  import ast
11
+ from server import *
12
 
13
  #http://localhost:8000
14
  app = FastAPI()
 
18
  def main():
19
  return "Hello World taha"
20
 
21
+ ##### use space /tmp/ ...
22
+
23
+
24
+ @app.post('/imageStep1')
25
+ async def image_step1(image_file: UploadFile = File(...),type_of_filters: str = Form(...), blur_radius: str = Form(...),):
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,blur_radius)
31
+
32
+ # Save the processed image to a temporary file
33
+ output_file_path_tmp = "/tmp/tmp_processed_image.png"
34
+ produced_image.save(output_file_path_tmp)
35
+
36
+ # Return the processed image for download
37
+ return FileResponse(output_file_path_tmp, media_type='image/png', filename="/tmp/tmp_processed_image.png")
38
+
39
+
40
+
41
+
42
+
43
 
44
  @app.post('/predict')
45
  async def predict(supported_types_str: str = Form(),age: str = Form() , file: UploadFile = File(...)):
 
60
  # Return the processed image for download
61
  return FileResponse(output_file_path, media_type='image/png', filename="/tmp/tmp_processed_image.png")
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
index.html CHANGED
@@ -2,11 +2,11 @@
2
  <body bgcolor="#00cccc">
3
  <center>
4
  <br><br><br>
5
- <form action="https://taha454-backg.hf.space/predict" method="post" enctype="multipart/form-data">
6
  <p><h3>Enter Image:</h3></p>
7
- Name :<p><input type="text" name="supported_types_str" /></p><br>
8
- Age :<p><input type="text" name="age" /></p><br>
9
- File : <input type="file" name="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
+ Name :<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
  <p><input type="submit" value="submit" /></p>
11
  </form>
12
  </center>