JustSkyDev commited on
Commit
0f2b7d6
·
1 Parent(s): c62fb0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -2,6 +2,9 @@ from PIL import Image
2
  from fastapi import FastAPI
3
  from process import Segment
4
  from pydantic import BaseModel
 
 
 
5
 
6
  class SegmentationBody(BaseModel):
7
  baseImage: str
@@ -21,4 +24,15 @@ def root_path():
21
 
22
  @app.post("/api/segment/")
23
  def api_segment(data: SegmentationBody):
24
- return { "image": process_image(data.baseImage) }
 
 
 
 
 
 
 
 
 
 
 
 
2
  from fastapi import FastAPI
3
  from process import Segment
4
  from pydantic import BaseModel
5
+ import numpy as np
6
+ import io
7
+ import base64
8
 
9
  class SegmentationBody(BaseModel):
10
  baseImage: str
 
24
 
25
  @app.post("/api/segment/")
26
  def api_segment(data: SegmentationBody):
27
+ # Convert base64 string to PIL Image
28
+ input_image = Image.open(io.BytesIO(base64.b64decode(data.baseImage)))
29
+
30
+ # Process the image
31
+ output_image = process_image(input_image)
32
+
33
+ # Convert PIL Image to base64 string
34
+ byte_arr = io.BytesIO()
35
+ output_image.save(byte_arr, format='JPEG')
36
+ encoded_image = base64.b64encode(byte_arr.getvalue()).decode('ascii')
37
+
38
+ return { "image": encoded_image }