Spaces:
Sleeping
Sleeping
staswrs
commited on
Commit
·
b5ef988
1
Parent(s):
b2a27a7
🔥 add generate settings
Browse files
app.py
CHANGED
@@ -1,111 +1,3 @@
|
|
1 |
-
# import os
|
2 |
-
# import subprocess
|
3 |
-
|
4 |
-
# # 🧹 Убираем pyenv, если вдруг остался .python-version
|
5 |
-
# os.environ.pop("PYENV_VERSION", None)
|
6 |
-
|
7 |
-
# # ⚙️ Устанавливаем torch и diso
|
8 |
-
# subprocess.run(["pip", "install", "torch", "wheel"], check=True)
|
9 |
-
|
10 |
-
# subprocess.run([
|
11 |
-
# "pip", "install", "--no-build-isolation",
|
12 |
-
# "diso@git+https://github.com/SarahWeiii/diso.git"
|
13 |
-
# ], check=True)
|
14 |
-
|
15 |
-
# # ✅ Только теперь импортируем всё остальное
|
16 |
-
# import gradio as gr
|
17 |
-
# import uuid
|
18 |
-
# import torch
|
19 |
-
# import zipfile
|
20 |
-
# import requests
|
21 |
-
|
22 |
-
# from inference_triposg import run_triposg
|
23 |
-
# from triposg.pipelines.pipeline_triposg import TripoSGPipeline
|
24 |
-
# from briarmbg import BriaRMBG
|
25 |
-
|
26 |
-
# # === Настройки устройства ===
|
27 |
-
# # device = "cuda" if torch.cuda.is_available() else "cpu"
|
28 |
-
# # dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
29 |
-
# # dtype = torch.float32
|
30 |
-
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
31 |
-
# dtype = torch.float16 if device == "cuda" else torch.float32
|
32 |
-
|
33 |
-
# # === Проверка и загрузка весов ===
|
34 |
-
# weights_dir = "pretrained_weights"
|
35 |
-
# triposg_path = os.path.join(weights_dir, "TripoSG")
|
36 |
-
# rmbg_path = os.path.join(weights_dir, "RMBG-1.4")
|
37 |
-
|
38 |
-
# if not (os.path.exists(triposg_path) and os.path.exists(rmbg_path)):
|
39 |
-
# print("📦 Downloading pretrained weights from Hugging Face Dataset...")
|
40 |
-
# url = "https://huggingface.co/datasets/endlesstools/pretrained-assets/resolve/main/pretrained_models.zip"
|
41 |
-
# zip_path = "pretrained_models.zip"
|
42 |
-
|
43 |
-
# with requests.get(url, stream=True) as r:
|
44 |
-
# r.raise_for_status()
|
45 |
-
# with open(zip_path, "wb") as f:
|
46 |
-
# for chunk in r.iter_content(chunk_size=8192):
|
47 |
-
# f.write(chunk)
|
48 |
-
|
49 |
-
# print("📦 Extracting weights...")
|
50 |
-
# with zipfile.ZipFile(zip_path, "r") as zip_ref:
|
51 |
-
# zip_ref.extractall(weights_dir)
|
52 |
-
|
53 |
-
# os.remove(zip_path)
|
54 |
-
# print("✅ Weights ready.")
|
55 |
-
|
56 |
-
# # === Загрузка моделей ===
|
57 |
-
# pipe = TripoSGPipeline.from_pretrained(triposg_path).to(device, dtype)
|
58 |
-
# rmbg_net = BriaRMBG.from_pretrained(rmbg_path).to(device)
|
59 |
-
# rmbg_net.eval()
|
60 |
-
|
61 |
-
# # === Функция генерации ===
|
62 |
-
# def generate(file):
|
63 |
-
# temp_id = str(uuid.uuid4())
|
64 |
-
# input_path = f"/tmp/{temp_id}.png"
|
65 |
-
# output_path = f"/tmp/{temp_id}.glb"
|
66 |
-
|
67 |
-
# with open(input_path, "wb") as f:
|
68 |
-
# f.write(file)
|
69 |
-
|
70 |
-
# print("[DEBUG] Generating mesh...")
|
71 |
-
# try:
|
72 |
-
# mesh = run_triposg(
|
73 |
-
# pipe=pipe,
|
74 |
-
# image_input=input_path,
|
75 |
-
# rmbg_net=rmbg_net,
|
76 |
-
# seed=42,
|
77 |
-
# num_inference_steps=25,
|
78 |
-
# guidance_scale=5.0,
|
79 |
-
# faces=-1,
|
80 |
-
# )
|
81 |
-
# # mesh.export(output_path)
|
82 |
-
# if mesh is None:
|
83 |
-
# raise ValueError("Mesh generation failed")
|
84 |
-
# mesh.export(output_path)
|
85 |
-
# print(f"[DEBUG] Mesh saved to {output_path}")
|
86 |
-
# # return output_path
|
87 |
-
# if os.path.exists(output_path):
|
88 |
-
# return output_path
|
89 |
-
# else:
|
90 |
-
# return "Error: mesh export failed or file not found"
|
91 |
-
# except Exception as e:
|
92 |
-
# print("[ERROR]", e)
|
93 |
-
# return f"Error: {e}"
|
94 |
-
|
95 |
-
# # === Gradio-интерфейс ===
|
96 |
-
# demo = gr.Interface(
|
97 |
-
# fn=generate,
|
98 |
-
# inputs=gr.File(type="binary", label="Upload image"),
|
99 |
-
# outputs=gr.File(label="Generated .glb model"),
|
100 |
-
# title="TripoSG Image-to-3D",
|
101 |
-
# description="Upload an image and get back a 3D GLB model.",
|
102 |
-
# )
|
103 |
-
|
104 |
-
# # # === ВАЖНО: переменная должна называться `app` ===
|
105 |
-
# # app = demo.launch(inline=True, share=False, prevent_thread_lock=True)
|
106 |
-
# demo.launch()
|
107 |
-
|
108 |
-
|
109 |
|
110 |
|
111 |
import os
|
@@ -166,7 +58,8 @@ rmbg_net = BriaRMBG.from_pretrained(rmbg_path).to(device)
|
|
166 |
rmbg_net.eval()
|
167 |
|
168 |
# Генерация .glb
|
169 |
-
def generate(image_path):
|
|
|
170 |
print("[API CALL] image_path received:", image_path)
|
171 |
print("[API CALL] File exists:", os.path.exists(image_path))
|
172 |
|
@@ -176,14 +69,23 @@ def generate(image_path):
|
|
176 |
print("[DEBUG] Generating mesh from:", image_path)
|
177 |
|
178 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
mesh = run_triposg(
|
180 |
pipe=pipe,
|
181 |
image_input=image_path,
|
182 |
rmbg_net=rmbg_net,
|
183 |
seed=42,
|
184 |
-
num_inference_steps=
|
185 |
-
guidance_scale=
|
186 |
-
faces
|
187 |
)
|
188 |
|
189 |
if mesh is None:
|
@@ -217,33 +119,3 @@ demo.launch()
|
|
217 |
|
218 |
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
# import gradio as gr
|
223 |
-
# import uuid
|
224 |
-
# import os
|
225 |
-
# import traceback
|
226 |
-
|
227 |
-
# def generate(image_path):
|
228 |
-
# try:
|
229 |
-
# print("[DEBUG] got image path:", image_path)
|
230 |
-
# print("[DEBUG] file exists:", os.path.exists(image_path))
|
231 |
-
|
232 |
-
# out_path = f"/tmp/{uuid.uuid4()}.txt"
|
233 |
-
# with open(out_path, "w") as f:
|
234 |
-
# f.write(f"Received: {image_path}")
|
235 |
-
|
236 |
-
# return out_path
|
237 |
-
|
238 |
-
# except Exception as e:
|
239 |
-
# print("[ERROR]", e)
|
240 |
-
# traceback.print_exc()
|
241 |
-
# return f"Error: {e}"
|
242 |
-
|
243 |
-
# demo = gr.Interface(
|
244 |
-
# fn=generate,
|
245 |
-
# inputs=gr.Image(type="filepath"),
|
246 |
-
# outputs=gr.File()
|
247 |
-
# )
|
248 |
-
|
249 |
-
# demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
|
3 |
import os
|
|
|
58 |
rmbg_net.eval()
|
59 |
|
60 |
# Генерация .glb
|
61 |
+
# def generate(image_path):
|
62 |
+
def generate(image_path, face_number=50000, guidance_scale=5.0, num_steps=25):
|
63 |
print("[API CALL] image_path received:", image_path)
|
64 |
print("[API CALL] File exists:", os.path.exists(image_path))
|
65 |
|
|
|
69 |
print("[DEBUG] Generating mesh from:", image_path)
|
70 |
|
71 |
try:
|
72 |
+
# mesh = run_triposg(
|
73 |
+
# pipe=pipe,
|
74 |
+
# image_input=image_path,
|
75 |
+
# rmbg_net=rmbg_net,
|
76 |
+
# seed=42,
|
77 |
+
# num_inference_steps=25,
|
78 |
+
# guidance_scale=5.0,
|
79 |
+
# faces=-1,
|
80 |
+
# )
|
81 |
mesh = run_triposg(
|
82 |
pipe=pipe,
|
83 |
image_input=image_path,
|
84 |
rmbg_net=rmbg_net,
|
85 |
seed=42,
|
86 |
+
num_inference_steps=int(num_steps),
|
87 |
+
guidance_scale=float(guidance_scale),
|
88 |
+
faces=int(face_number),
|
89 |
)
|
90 |
|
91 |
if mesh is None:
|
|
|
119 |
|
120 |
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|