Spaces:
Runtime error
Runtime error
:tada: initial commit
Browse files- .gitignore +2 -0
- README.md +2 -2
- app.py +33 -0
- requirements.txt +9 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.idea/
|
| 2 |
+
venv/
|
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
title: SAM And ProPainter
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: pink
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 4.0.2
|
| 8 |
app_file: app.py
|
|
|
|
| 1 |
---
|
| 2 |
title: SAM And ProPainter
|
| 3 |
+
emoji: π¨
|
| 4 |
colorFrom: pink
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 4.0.2
|
| 8 |
app_file: app.py
|
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import torch
|
| 5 |
+
from PIL import Image
|
| 6 |
+
from transformers import SamModel, SamProcessor
|
| 7 |
+
|
| 8 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 9 |
+
MODEL = SamModel.from_pretrained("facebook/sam-vit-large").to(DEVICE)
|
| 10 |
+
PROCESSOR = SamProcessor.from_pretrained("facebook/sam-vit-large")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def inference(masked_image: Dict[str, Image.Image]) -> Image.Image:
|
| 14 |
+
image = masked_image['image']
|
| 15 |
+
mask = masked_image['mask'].resize((256, 256), Image.Resampling.LANCZOS)
|
| 16 |
+
return image
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
with gr.Blocks() as demo:
|
| 20 |
+
with gr.Row():
|
| 21 |
+
with gr.Column():
|
| 22 |
+
input_image = gr.Image(
|
| 23 |
+
image_mode='RGB', type='pil', tool="sketch", interactive=True,
|
| 24 |
+
brush_radius=20.0, brush_color="#FFFFFF", height=500)
|
| 25 |
+
submit_button = gr.Button("Submit")
|
| 26 |
+
output_image = gr.Image(image_mode='RGB', type='pil')
|
| 27 |
+
|
| 28 |
+
submit_button.click(
|
| 29 |
+
inference,
|
| 30 |
+
inputs=[input_image],
|
| 31 |
+
outputs=output_image)
|
| 32 |
+
|
| 33 |
+
demo.launch(debug=False, show_error=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
--extra-index-url https://download.pytorch.org/whl/cu118
|
| 2 |
+
torch
|
| 3 |
+
torchvision
|
| 4 |
+
|
| 5 |
+
numpy
|
| 6 |
+
pillow
|
| 7 |
+
gradio==3.50.2
|
| 8 |
+
transformers
|
| 9 |
+
supervision
|