Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -65,8 +65,6 @@ def glb_to_data_url(glb_path: str) -> str:
|
|
| 65 |
# ---------------------------
|
| 66 |
# Sambanova DeepseekR1 Clients and Chat Function
|
| 67 |
# ---------------------------
|
| 68 |
-
|
| 69 |
-
#deepseek-ai/DeepSeek-R1-Distill-Llama-70B
|
| 70 |
sambanova_client = openai.OpenAI(
|
| 71 |
api_key=os.environ.get("SAMBANOVA_API_KEY"),
|
| 72 |
base_url="https://api.sambanova.ai/v1",
|
|
@@ -130,7 +128,6 @@ class Model:
|
|
| 130 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 131 |
self.pipe = ShapEPipeline.from_pretrained("openai/shap-e", torch_dtype=torch.float16)
|
| 132 |
self.pipe.to(self.device)
|
| 133 |
-
# Ensure the text encoder is in half precision to avoid dtype mismatches.
|
| 134 |
if torch.cuda.is_available():
|
| 135 |
try:
|
| 136 |
self.pipe.text_encoder = self.pipe.text_encoder.half()
|
|
@@ -139,7 +136,6 @@ class Model:
|
|
| 139 |
|
| 140 |
self.pipe_img = ShapEImg2ImgPipeline.from_pretrained("openai/shap-e-img2img", torch_dtype=torch.float16)
|
| 141 |
self.pipe_img.to(self.device)
|
| 142 |
-
# Use getattr with a default value to avoid AttributeError if text_encoder is missing.
|
| 143 |
if torch.cuda.is_available():
|
| 144 |
text_encoder_img = getattr(self.pipe_img, "text_encoder", None)
|
| 145 |
if text_encoder_img is not None:
|
|
@@ -147,7 +143,6 @@ class Model:
|
|
| 147 |
|
| 148 |
def to_glb(self, ply_path: str) -> str:
|
| 149 |
mesh = trimesh.load(ply_path)
|
| 150 |
-
# Rotate the mesh for proper orientation
|
| 151 |
rot = trimesh.transformations.rotation_matrix(-np.pi / 2, [1, 0, 0])
|
| 152 |
mesh.apply_transform(rot)
|
| 153 |
rot = trimesh.transformations.rotation_matrix(np.pi, [0, 1, 0])
|
|
@@ -379,7 +374,7 @@ def clean_chat_history(chat_history):
|
|
| 379 |
# ---------------------------
|
| 380 |
# Stable Diffusion XL Pipeline for Image Generation
|
| 381 |
# ---------------------------
|
| 382 |
-
MODEL_ID_SD = os.getenv("MODEL_VAL_PATH")
|
| 383 |
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))
|
| 384 |
USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
|
| 385 |
ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
|
|
@@ -593,7 +588,7 @@ def generate(
|
|
| 593 |
# --- DeepSeek-R1 branch ---
|
| 594 |
if text.strip().lower().startswith("@deepseekr1"):
|
| 595 |
prompt = text[len("@deepseekr1"):].strip()
|
| 596 |
-
|
| 597 |
response = chat_response(prompt)
|
| 598 |
yield response
|
| 599 |
return
|
|
|
|
| 65 |
# ---------------------------
|
| 66 |
# Sambanova DeepseekR1 Clients and Chat Function
|
| 67 |
# ---------------------------
|
|
|
|
|
|
|
| 68 |
sambanova_client = openai.OpenAI(
|
| 69 |
api_key=os.environ.get("SAMBANOVA_API_KEY"),
|
| 70 |
base_url="https://api.sambanova.ai/v1",
|
|
|
|
| 128 |
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 129 |
self.pipe = ShapEPipeline.from_pretrained("openai/shap-e", torch_dtype=torch.float16)
|
| 130 |
self.pipe.to(self.device)
|
|
|
|
| 131 |
if torch.cuda.is_available():
|
| 132 |
try:
|
| 133 |
self.pipe.text_encoder = self.pipe.text_encoder.half()
|
|
|
|
| 136 |
|
| 137 |
self.pipe_img = ShapEImg2ImgPipeline.from_pretrained("openai/shap-e-img2img", torch_dtype=torch.float16)
|
| 138 |
self.pipe_img.to(self.device)
|
|
|
|
| 139 |
if torch.cuda.is_available():
|
| 140 |
text_encoder_img = getattr(self.pipe_img, "text_encoder", None)
|
| 141 |
if text_encoder_img is not None:
|
|
|
|
| 143 |
|
| 144 |
def to_glb(self, ply_path: str) -> str:
|
| 145 |
mesh = trimesh.load(ply_path)
|
|
|
|
| 146 |
rot = trimesh.transformations.rotation_matrix(-np.pi / 2, [1, 0, 0])
|
| 147 |
mesh.apply_transform(rot)
|
| 148 |
rot = trimesh.transformations.rotation_matrix(np.pi, [0, 1, 0])
|
|
|
|
| 374 |
# ---------------------------
|
| 375 |
# Stable Diffusion XL Pipeline for Image Generation
|
| 376 |
# ---------------------------
|
| 377 |
+
MODEL_ID_SD = os.getenv("MODEL_VAL_PATH")
|
| 378 |
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "4096"))
|
| 379 |
USE_TORCH_COMPILE = os.getenv("USE_TORCH_COMPILE", "0") == "1"
|
| 380 |
ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
|
|
|
|
| 588 |
# --- DeepSeek-R1 branch ---
|
| 589 |
if text.strip().lower().startswith("@deepseekr1"):
|
| 590 |
prompt = text[len("@deepseekr1"):].strip()
|
| 591 |
+
# Directly return the response from the API
|
| 592 |
response = chat_response(prompt)
|
| 593 |
yield response
|
| 594 |
return
|