Spaces:
Sleeping
Sleeping
Commit
·
a12f9e6
1
Parent(s):
519b661
Upload app.py after modify fastsam imports
Browse files
app.py
CHANGED
@@ -1,31 +1,14 @@
|
|
1 |
import os
|
2 |
-
import cv2
|
3 |
import numpy as np
|
4 |
from PIL import Image
|
5 |
import gradio as gr
|
6 |
-
import json
|
7 |
-
import matplotlib.pyplot as plt
|
8 |
-
import subprocess
|
9 |
-
|
10 |
-
repo_url = "https://github.com/CASIA-IVA-Lab/FastSAM.git"
|
11 |
-
target_directory = "./FastSAM"
|
12 |
-
subprocess.run(['git', 'clone', repo_url, target_directory])
|
13 |
-
os.chdir('./FastSAM')
|
14 |
-
print('pwd: ', os.getcwd())
|
15 |
-
|
16 |
-
from fastsam import FastSAM, FastSAMPrompt
|
17 |
-
import ast
|
18 |
import torch
|
19 |
-
|
20 |
-
from
|
21 |
|
22 |
def gradio_fn(pil_input_img):
|
23 |
# load model
|
24 |
model = FastSAM('./weights/FastSAM.pt')
|
25 |
-
args_point_prompt = ast.literal_eval("[[0,0]]")
|
26 |
-
args_box_prompt = convert_box_xywh_to_xyxy(ast.literal_eval("[[0,0,0,0]]"))
|
27 |
-
args_point_label = ast.literal_eval("[0]")
|
28 |
-
args_text_prompt = None
|
29 |
input = pil_input_img
|
30 |
input = input.convert("RGB")
|
31 |
everything_results = model(
|
@@ -40,19 +23,7 @@ def gradio_fn(pil_input_img):
|
|
40 |
points = None
|
41 |
point_label = None
|
42 |
prompt_process = FastSAMPrompt(input, everything_results, device="cpu")
|
43 |
-
|
44 |
-
ann = prompt_process.box_prompt(bboxes=args_box_prompt)
|
45 |
-
bboxes = args_box_prompt
|
46 |
-
elif args_text_prompt != None:
|
47 |
-
ann = prompt_process.text_prompt(text=args_text_prompt)
|
48 |
-
elif args_point_prompt[0] != [0, 0]:
|
49 |
-
ann = prompt_process.point_prompt(
|
50 |
-
points=args_point_prompt, pointlabel=args_point_label
|
51 |
-
)
|
52 |
-
points = args_point_prompt
|
53 |
-
point_label = args_point_label
|
54 |
-
else:
|
55 |
-
ann = prompt_process.everything_prompt()
|
56 |
prompt_process.plot(
|
57 |
annotations=ann,
|
58 |
output_path="./output.jpg",
|
@@ -73,4 +44,6 @@ demo = gr.Interface(fn=gradio_fn,
|
|
73 |
description="- **FastSAM** model that returns segmented RGB image of given input image. \
|
74 |
- **Credits** : \
|
75 |
- https://huggingface.co/An-619 \
|
76 |
-
- https://github.com/CASIA-IVA-Lab/FastSAM")
|
|
|
|
|
|
1 |
import os
|
|
|
2 |
import numpy as np
|
3 |
from PIL import Image
|
4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import torch
|
6 |
+
import matplotlib.pyplot as plt
|
7 |
+
from fastsam import FastSAM, FastSAMPrompt
|
8 |
|
9 |
def gradio_fn(pil_input_img):
|
10 |
# load model
|
11 |
model = FastSAM('./weights/FastSAM.pt')
|
|
|
|
|
|
|
|
|
12 |
input = pil_input_img
|
13 |
input = input.convert("RGB")
|
14 |
everything_results = model(
|
|
|
23 |
points = None
|
24 |
point_label = None
|
25 |
prompt_process = FastSAMPrompt(input, everything_results, device="cpu")
|
26 |
+
ann = prompt_process.everything_prompt()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
prompt_process.plot(
|
28 |
annotations=ann,
|
29 |
output_path="./output.jpg",
|
|
|
44 |
description="- **FastSAM** model that returns segmented RGB image of given input image. \
|
45 |
- **Credits** : \
|
46 |
- https://huggingface.co/An-619 \
|
47 |
+
- https://github.com/CASIA-IVA-Lab/FastSAM")
|
48 |
+
|
49 |
+
demo.launch(share=True)
|