Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
fdcc6ec
1
Parent(s):
39cf56c
update
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from gradio_client import Client
|
| 3 |
import spaces
|
| 4 |
|
| 5 |
import os
|
|
@@ -15,6 +15,7 @@ from typing import *
|
|
| 15 |
import torch
|
| 16 |
import numpy as np
|
| 17 |
from PIL import Image
|
|
|
|
| 18 |
from trellis2.modules.sparse import SparseTensor
|
| 19 |
from trellis2.pipelines import Trellis2ImageTo3DPipeline
|
| 20 |
from trellis2.renderers import EnvMap
|
|
@@ -38,9 +39,12 @@ def end_session(req: gr.Request):
|
|
| 38 |
|
| 39 |
|
| 40 |
def remove_background(input: Image.Image) -> Image.Image:
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
def preprocess_image(input: Image.Image) -> Image.Image:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gradio_client import Client, handle_file
|
| 3 |
import spaces
|
| 4 |
|
| 5 |
import os
|
|
|
|
| 15 |
import torch
|
| 16 |
import numpy as np
|
| 17 |
from PIL import Image
|
| 18 |
+
import tempfile
|
| 19 |
from trellis2.modules.sparse import SparseTensor
|
| 20 |
from trellis2.pipelines import Trellis2ImageTo3DPipeline
|
| 21 |
from trellis2.renderers import EnvMap
|
|
|
|
| 39 |
|
| 40 |
|
| 41 |
def remove_background(input: Image.Image) -> Image.Image:
|
| 42 |
+
with tempfile.NamedTemporaryFile(suffix='.png') as f:
|
| 43 |
+
input = input.convert('RGB')
|
| 44 |
+
input.save(f.name)
|
| 45 |
+
output = rmbg_client.predict(handle_file(f.name), api_name="/image")[0][0]
|
| 46 |
+
output = Image.open(output)
|
| 47 |
+
return output
|
| 48 |
|
| 49 |
|
| 50 |
def preprocess_image(input: Image.Image) -> Image.Image:
|