JustSkyDev commited on
Commit ·
d29353c
1
Parent(s): fd03c7b
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
from process import Segment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
def process_image(input_image):
|
| 6 |
# Convert the input image to PIL.Image format if it's not
|
| 7 |
if not isinstance(input_image, Image.Image):
|
| 8 |
input_image = Image.fromarray(input_image.astype('uint8'), 'RGB')
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
from process import Segment
|
| 4 |
+
from fastapi import FastAPI
|
| 5 |
+
from pydantic import BaseModel
|
| 6 |
+
import base64
|
| 7 |
+
import io
|
| 8 |
+
|
| 9 |
+
app = FastAPI()
|
| 10 |
+
|
| 11 |
+
class Item(BaseModel):
|
| 12 |
+
base64: str
|
| 13 |
+
|
| 14 |
+
@app.post("/api/segment")
|
| 15 |
+
async def create_item(item: Item):
|
| 16 |
+
format, imgstr = item.base64.split(';base64,')
|
| 17 |
+
ext = format.split('/')[-1]
|
| 18 |
+
data = base64.b64decode(imgstr)
|
| 19 |
+
input_image = Image.open(io.BytesIO(data))
|
| 20 |
|
|
|
|
| 21 |
# Convert the input image to PIL.Image format if it's not
|
| 22 |
if not isinstance(input_image, Image.Image):
|
| 23 |
input_image = Image.fromarray(input_image.astype('uint8'), 'RGB')
|