Spaces:
Running
on
Zero
Running
on
Zero
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -5,6 +5,24 @@ from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
|
| 5 |
from qwen_vl_utils import process_vision_info
|
| 6 |
import html
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
sys_prompt = """First output the the types of degradations in image briefly in <TYPE> <TYPE_END> tags,
|
| 9 |
and then output what effects do these degradation have on the image in <INFLUENCE> <INFLUENCE_END> tags,
|
| 10 |
then based on the strength of degradation, output an APPROPRIATE length for the reasoning process in <REASONING> <REASONING_END> tags,
|
|
@@ -13,10 +31,8 @@ sys_prompt = """First output the the types of degradations in image briefly in <
|
|
| 13 |
|
| 14 |
project_dir = os.path.dirname(os.path.abspath(__file__))
|
| 15 |
|
| 16 |
-
is_spaces = os.getenv("SPACE_ID") is not None
|
| 17 |
-
# temp_dir = os.path.join(project_dir, ".gradio_temp")
|
| 18 |
-
temp_dir = project_dir
|
| 19 |
if not is_spaces:
|
|
|
|
| 20 |
os.makedirs(temp_dir, exist_ok=True)
|
| 21 |
os.environ["GRADIO_TEMP_DIR"] = temp_dir
|
| 22 |
|
|
|
|
| 5 |
from qwen_vl_utils import process_vision_info
|
| 6 |
import html
|
| 7 |
|
| 8 |
+
# 导入 spaces 模块用于 GPU 检测
|
| 9 |
+
is_spaces = os.getenv("SPACE_ID") is not None
|
| 10 |
+
spaces_available = False
|
| 11 |
+
GPU = None
|
| 12 |
+
|
| 13 |
+
if is_spaces:
|
| 14 |
+
try:
|
| 15 |
+
from spaces import GPU
|
| 16 |
+
spaces_available = True
|
| 17 |
+
except ImportError:
|
| 18 |
+
print("⚠️ spaces module not available, GPU detection may not work")
|
| 19 |
+
|
| 20 |
+
# 创建条件装饰器
|
| 21 |
+
def gpu_decorator(func):
|
| 22 |
+
"""条件应用 GPU 装饰器"""
|
| 23 |
+
if spaces_available and GPU is not None:
|
| 24 |
+
return GPU(func)
|
| 25 |
+
return func
|
| 26 |
sys_prompt = """First output the the types of degradations in image briefly in <TYPE> <TYPE_END> tags,
|
| 27 |
and then output what effects do these degradation have on the image in <INFLUENCE> <INFLUENCE_END> tags,
|
| 28 |
then based on the strength of degradation, output an APPROPRIATE length for the reasoning process in <REASONING> <REASONING_END> tags,
|
|
|
|
| 31 |
|
| 32 |
project_dir = os.path.dirname(os.path.abspath(__file__))
|
| 33 |
|
|
|
|
|
|
|
|
|
|
| 34 |
if not is_spaces:
|
| 35 |
+
temp_dir = os.path.join(project_dir, ".gradio_temp")
|
| 36 |
os.makedirs(temp_dir, exist_ok=True)
|
| 37 |
os.environ["GRADIO_TEMP_DIR"] = temp_dir
|
| 38 |
|