Spaces:
Running
on
Zero
Running
on
Zero
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -24,20 +24,9 @@ def gpu_decorator(func):
|
|
| 24 |
return GPU(func)
|
| 25 |
return func
|
| 26 |
|
| 27 |
-
# 条件安装 flash-attn
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
import subprocess
|
| 31 |
-
print("🔧 Installing flash-attn for GPU acceleration...")
|
| 32 |
-
subprocess.run(
|
| 33 |
-
'pip install flash-attn --no-build-isolation',
|
| 34 |
-
env={'FLASH_ATTENTION_SKIP_CUDA_BUILD': "TRUE"},
|
| 35 |
-
shell=True,
|
| 36 |
-
check=False
|
| 37 |
-
)
|
| 38 |
-
print("✅ flash-attn installation completed")
|
| 39 |
-
except Exception as e:
|
| 40 |
-
print(f"⚠️ flash-attn installation failed (will use eager attention): {e}")
|
| 41 |
|
| 42 |
sys_prompt = """First output the the types of degradations in image briefly in <TYPE> <TYPE_END> tags,
|
| 43 |
and then output what effects do these degradation have on the image in <INFLUENCE> <INFLUENCE_END> tags,
|
|
@@ -65,7 +54,6 @@ class ModelHandler:
|
|
| 65 |
self.processor = None
|
| 66 |
self._load_model()
|
| 67 |
|
| 68 |
-
@gpu_decorator # 标记此函数需要 GPU
|
| 69 |
def _load_model(self):
|
| 70 |
try:
|
| 71 |
print(f"⏳ Loading model weights, this may take a few minutes...")
|
|
@@ -322,19 +310,7 @@ def create_chat_ui():
|
|
| 322 |
|
| 323 |
return demo
|
| 324 |
|
| 325 |
-
# 在启动时声明需要 GPU(用于 ZeroGPU 检测)
|
| 326 |
-
@gpu_decorator
|
| 327 |
-
def initialize_gpu():
|
| 328 |
-
"""初始化 GPU,用于 Spaces 检测"""
|
| 329 |
-
if is_spaces:
|
| 330 |
-
print("✅ GPU declared for Hugging Face Spaces")
|
| 331 |
-
return True
|
| 332 |
-
|
| 333 |
if __name__ == "__main__":
|
| 334 |
-
# 在启动时调用以声明 GPU
|
| 335 |
-
if is_spaces:
|
| 336 |
-
initialize_gpu()
|
| 337 |
-
|
| 338 |
demo = create_chat_ui()
|
| 339 |
|
| 340 |
custom_css = """
|
|
|
|
| 24 |
return GPU(func)
|
| 25 |
return func
|
| 26 |
|
| 27 |
+
# 条件安装 flash-attn(延迟到模型加载时,避免启动时 CUDA 检查)
|
| 28 |
+
# 注意:在 ZeroGPU 环境中,启动时 CUDA 可能还不可用
|
| 29 |
+
# flash-attn 将在模型加载时根据实际 CUDA 可用性决定是否使用
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
sys_prompt = """First output the the types of degradations in image briefly in <TYPE> <TYPE_END> tags,
|
| 32 |
and then output what effects do these degradation have on the image in <INFLUENCE> <INFLUENCE_END> tags,
|
|
|
|
| 54 |
self.processor = None
|
| 55 |
self._load_model()
|
| 56 |
|
|
|
|
| 57 |
def _load_model(self):
|
| 58 |
try:
|
| 59 |
print(f"⏳ Loading model weights, this may take a few minutes...")
|
|
|
|
| 310 |
|
| 311 |
return demo
|
| 312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
demo = create_chat_ui()
|
| 315 |
|
| 316 |
custom_css = """
|