Spaces:
Running
Running
Commit
·
3ee92ac
1
Parent(s):
deaa788
init
Browse files- README.md +4 -4
- app.py +89 -0
- images/earth_1.jpg +0 -0
- images/earth_2.jpg +0 -0
- images/earth_3.jpg +0 -0
- images/hmbb_1.jpg +0 -0
- images/hmbb_2.jpg +0 -0
- images/hmbb_3.jpg +0 -0
- images/obj_1.jpg +0 -0
- images/obj_2.jpg +0 -0
- images/obj_3.jpg +0 -0
- images/rainbow_1.jpg +0 -0
- images/rainbow_2.jpg +0 -0
- images/rainbow_3.jpg +0 -0
- images/xray_1.jpg +0 -0
- images/xray_2.jpg +0 -0
- images/xray_3.jpg +0 -0
- images/ydt_1.jpg +0 -0
- images/ydt_2.jpg +0 -0
- images/ydt_3.jpg +0 -0
- seggpt_teaser.png +0 -0
README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
---
|
| 2 |
title: SegGPT
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 3.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
|
|
| 1 |
---
|
| 2 |
title: SegGPT
|
| 3 |
+
emoji: 🏢
|
| 4 |
+
colorFrom: gray
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 3.22.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
app.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
import io
|
| 5 |
+
import requests
|
| 6 |
+
import json
|
| 7 |
+
import base64
|
| 8 |
+
from PIL import Image
|
| 9 |
+
import numpy as np
|
| 10 |
+
import gradio as gr
|
| 11 |
+
|
| 12 |
+
def inference_mask1(prompt,
|
| 13 |
+
img,
|
| 14 |
+
img_):
|
| 15 |
+
files = {
|
| 16 |
+
"pimage" : resizeImg(prompt["image"]),
|
| 17 |
+
"pmask" : resizeImg(prompt["mask"]),
|
| 18 |
+
"img" : resizeImg(img),
|
| 19 |
+
"img_" : resizeImg(img_)
|
| 20 |
+
}
|
| 21 |
+
r = requests.post("https://flagstudio.baai.ac.cn/painter/run", json = files)
|
| 22 |
+
a = json.loads(r.text)
|
| 23 |
+
res = []
|
| 24 |
+
for i in range(len(a)):
|
| 25 |
+
res.append(np.uint8(np.array(Image.open(io.BytesIO(base64.b64decode(a[i]))))))
|
| 26 |
+
return res
|
| 27 |
+
|
| 28 |
+
def resizeImg(img):
|
| 29 |
+
res, hres = 448, 448
|
| 30 |
+
img = Image.fromarray(img).convert("RGB")
|
| 31 |
+
img = img.resize((res, hres))
|
| 32 |
+
temp = io.BytesIO()
|
| 33 |
+
img.save(temp, format="WEBP")
|
| 34 |
+
return base64.b64encode(temp.getvalue()).decode('ascii')
|
| 35 |
+
|
| 36 |
+
def inference_mask_cat(
|
| 37 |
+
prompt,
|
| 38 |
+
img,
|
| 39 |
+
img_,
|
| 40 |
+
):
|
| 41 |
+
output_list = [img, img_]
|
| 42 |
+
return output_list
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# define app features and run
|
| 46 |
+
|
| 47 |
+
examples = [
|
| 48 |
+
['./images/hmbb_1.jpg', './images/hmbb_2.jpg', './images/hmbb_3.jpg'],
|
| 49 |
+
['./images/rainbow_1.jpg', './images/rainbow_2.jpg', './images/rainbow_3.jpg'],
|
| 50 |
+
['./images/earth_1.jpg', './images/earth_2.jpg', './images/earth_3.jpg'],
|
| 51 |
+
['./images/obj_1.jpg', './images/obj_2.jpg', './images/obj_3.jpg'],
|
| 52 |
+
['./images/xray_1.jpg', './images/xray_2.jpg', './images/xray_3.jpg'],
|
| 53 |
+
['./images/ydt_2.jpg', './images/ydt_1.jpg', './images/ydt_3.jpg'],
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
demo_mask = gr.Interface(fn=inference_mask1,
|
| 57 |
+
inputs=[gr.ImageMask(label="prompt (提示图)"), gr.Image(label="img1 (测试图1)"), gr.Image(label="img2 (测试图2)")],
|
| 58 |
+
outputs=gr.Gallery(label="outputs (输出图)"),
|
| 59 |
+
examples=examples,
|
| 60 |
+
#title="SegGPT for Any Segmentation<br>(Painter Inside)",
|
| 61 |
+
description="<p> \
|
| 62 |
+
Choose an example below 🔥 🔥 🔥 <br>\
|
| 63 |
+
Or, upload by yourself: <br>\
|
| 64 |
+
1. Upload images to be tested to 'img1' and/or 'img2'. <br>2. Upload a prompt image to 'prompt' and draw a mask. <br>\
|
| 65 |
+
Tips: The more accurate you annotate, the more accurate the model predicts.;) \
|
| 66 |
+
</p>",
|
| 67 |
+
cache_examples=False,
|
| 68 |
+
allow_flagging="never",
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
title = "SegGPT: Segmenting Everything In Context<br> \
|
| 73 |
+
<div align='center'> \
|
| 74 |
+
<h2><a href='https://arxiv.org/abs/2304.03284' target='_blank' rel='noopener'>[paper]</a> \
|
| 75 |
+
<a href='https://github.com/baaivision/Painter' target='_blank' rel='noopener'>[code]</a></h2> \
|
| 76 |
+
<br> \
|
| 77 |
+
<image src='file/seggpt_teaser.png' width='720px' /> \
|
| 78 |
+
<h2>SegGPT performs arbitrary segmentation tasks in images or videos via in-context inference, such as object instance, stuff, part, contour, and text, with only one single model.</h2> \
|
| 79 |
+
</div> \
|
| 80 |
+
"
|
| 81 |
+
|
| 82 |
+
demo = gr.TabbedInterface([demo_mask, ], ['General 1-shot', ], title=title)
|
| 83 |
+
|
| 84 |
+
#demo.launch(share=True, auth=("baai", "vision"))
|
| 85 |
+
demo.launch()
|
| 86 |
+
#demo.launch(server_name="0.0.0.0", server_port=34311)
|
| 87 |
+
# -
|
| 88 |
+
|
| 89 |
+
|
images/earth_1.jpg
ADDED
|
images/earth_2.jpg
ADDED
|
images/earth_3.jpg
ADDED
|
images/hmbb_1.jpg
ADDED
|
images/hmbb_2.jpg
ADDED
|
images/hmbb_3.jpg
ADDED
|
images/obj_1.jpg
ADDED
|
images/obj_2.jpg
ADDED
|
images/obj_3.jpg
ADDED
|
images/rainbow_1.jpg
ADDED
|
images/rainbow_2.jpg
ADDED
|
images/rainbow_3.jpg
ADDED
|
images/xray_1.jpg
ADDED
|
images/xray_2.jpg
ADDED
|
images/xray_3.jpg
ADDED
|
images/ydt_1.jpg
ADDED
|
images/ydt_2.jpg
ADDED
|
images/ydt_3.jpg
ADDED
|
seggpt_teaser.png
ADDED
|