Spaces:
Runtime error
Runtime error
fix zerogpu bugs
Browse files
.gitignore
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
**/.eggs/
|
| 2 |
*.so
|
| 3 |
-
JarvisIR/package/agent_tools/RIDCP/.eggs
|
|
|
|
|
|
| 1 |
**/.eggs/
|
| 2 |
*.so
|
| 3 |
+
JarvisIR/package/agent_tools/RIDCP/.eggs
|
| 4 |
+
JarvisIR/checkpoints
|
JarvisIR/package/agent_tools/Retinexformer/basicsr_retinexformer/version.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# GENERATED VERSION FILE
|
| 2 |
-
# TIME: Tue Jun 10
|
| 3 |
__version__ = '1.2.0+unknown'
|
| 4 |
short_version = '1.2.0'
|
| 5 |
version_info = (1, 2, 0)
|
|
|
|
| 1 |
# GENERATED VERSION FILE
|
| 2 |
+
# TIME: Tue Jun 10 11:41:53 2025
|
| 3 |
__version__ = '1.2.0+unknown'
|
| 4 |
short_version = '1.2.0'
|
| 5 |
version_info = (1, 2, 0)
|
JarvisIR/package/agent_tools/img2img_turbo/inference.py
CHANGED
|
@@ -15,7 +15,7 @@ def load_turbo_model(name, model_path, device):
|
|
| 15 |
model.direction = 'b2a'
|
| 16 |
model.caption = 'driving in the day'
|
| 17 |
model.eval()
|
| 18 |
-
model.unet.enable_xformers_memory_efficient_attention()
|
| 19 |
return model
|
| 20 |
|
| 21 |
|
|
|
|
| 15 |
model.direction = 'b2a'
|
| 16 |
model.caption = 'driving in the day'
|
| 17 |
model.eval()
|
| 18 |
+
# model.unet.enable_xformers_memory_efficient_attention()
|
| 19 |
return model
|
| 20 |
|
| 21 |
|
app.py
CHANGED
|
@@ -7,37 +7,60 @@ import torch
|
|
| 7 |
from PIL import Image
|
| 8 |
from transformers import AutoProcessor, LlavaForConditionalGeneration, TextIteratorStreamer
|
| 9 |
from threading import Thread
|
| 10 |
-
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
os.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
files = list_files_info(repo_id="LYL1015/JarvisIR", repo_type="model")
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# Model configuration
|
| 39 |
# XXX: Path to the fine-tuned LLaVA model
|
| 40 |
-
model_id =
|
| 41 |
|
| 42 |
# Available image restoration tasks and their corresponding models
|
| 43 |
all_tasks = " {denoise: [scunet, restormer], lighten: [retinexformer_fivek, hvicidnet, lightdiff], \
|
|
@@ -73,13 +96,13 @@ prompts_query2 = [
|
|
| 73 |
print("Loading LLM model...")
|
| 74 |
|
| 75 |
# Initialize the image restoration toolkit
|
|
|
|
| 76 |
tool_engine = RestorationToolkit(score_weight=[0,0,0,0,0])
|
| 77 |
# Load the LLaVA model in half precision to reduce memory usage
|
| 78 |
model = LlavaForConditionalGeneration.from_pretrained(
|
| 79 |
model_id,
|
| 80 |
-
subfolder="pretrained/preview", # 关键参数:指定子目录
|
| 81 |
torch_dtype=torch.float16,
|
| 82 |
-
device_map="auto",
|
| 83 |
low_cpu_mem_usage=True
|
| 84 |
)
|
| 85 |
processor = AutoProcessor.from_pretrained(model_id)
|
|
@@ -198,7 +221,6 @@ def resize_image_to_original(processed_image_path, original_size):
|
|
| 198 |
return output_path
|
| 199 |
return processed_image_path
|
| 200 |
|
| 201 |
-
@spaces.GPU(duration=150)
|
| 202 |
def get_llm_response_streaming(image_path):
|
| 203 |
"""
|
| 204 |
Get streaming response from LLM for image analysis
|
|
@@ -236,7 +258,7 @@ def get_llm_response_streaming(image_path):
|
|
| 236 |
|
| 237 |
return streamer
|
| 238 |
|
| 239 |
-
|
| 240 |
def process_image_with_tools(image_path, models, original_size):
|
| 241 |
"""
|
| 242 |
Process image using the tool engine and restore to original size
|
|
@@ -262,7 +284,7 @@ def process_image_with_tools(image_path, models, original_size):
|
|
| 262 |
final_result = resize_image_to_original(res['output_path'], original_size)
|
| 263 |
|
| 264 |
return final_result
|
| 265 |
-
|
| 266 |
def process_full_pipeline(image):
|
| 267 |
"""
|
| 268 |
Main processing pipeline with streaming UI updates
|
|
|
|
| 7 |
from PIL import Image
|
| 8 |
from transformers import AutoProcessor, LlavaForConditionalGeneration, TextIteratorStreamer
|
| 9 |
from threading import Thread
|
| 10 |
+
import subprocess
|
| 11 |
|
| 12 |
+
def install_cuda_toolkit():
|
| 13 |
+
CUDA_TOOLKIT_URL = "https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run"
|
| 14 |
+
CUDA_TOOLKIT_FILE = "/tmp/%s" % os.path.basename(CUDA_TOOLKIT_URL)
|
| 15 |
+
subprocess.call(["wget", "-q", CUDA_TOOLKIT_URL, "-O", CUDA_TOOLKIT_FILE])
|
| 16 |
+
subprocess.call(["chmod", "+x", CUDA_TOOLKIT_FILE])
|
| 17 |
+
subprocess.call([CUDA_TOOLKIT_FILE, "--silent", "--toolkit"])
|
| 18 |
|
| 19 |
+
os.environ["CUDA_HOME"] = "/usr/local/cuda"
|
| 20 |
+
os.environ["PATH"] = "%s/bin:%s" % (os.environ["CUDA_HOME"], os.environ["PATH"])
|
| 21 |
+
os.environ["LD_LIBRARY_PATH"] = "%s/lib:%s" % (
|
| 22 |
+
os.environ["CUDA_HOME"],
|
| 23 |
+
"" if "LD_LIBRARY_PATH" not in os.environ else os.environ["LD_LIBRARY_PATH"],
|
| 24 |
+
)
|
| 25 |
+
# Fix: arch_list[-1] += '+PTX'; IndexError: list index out of range
|
| 26 |
+
os.environ["TORCH_CUDA_ARCH_LIST"] = "8.0;8.6"
|
| 27 |
|
| 28 |
+
install_cuda_toolkit()
|
|
|
|
| 29 |
|
| 30 |
+
def download_tools_ckpts(target_dir, url):
|
| 31 |
+
from huggingface_hub import snapshot_download
|
| 32 |
+
import os
|
| 33 |
+
import shutil
|
| 34 |
+
|
| 35 |
+
tmp_dir = "hf_temp_download"
|
| 36 |
+
os.makedirs(tmp_dir, exist_ok=True)
|
| 37 |
+
|
| 38 |
+
snapshot_download(
|
| 39 |
+
repo_id="LYL1015/JarvisIR",
|
| 40 |
+
repo_type="model",
|
| 41 |
+
local_dir=tmp_dir,
|
| 42 |
+
allow_patterns=os.path.join(url, "**"),
|
| 43 |
+
local_dir_use_symlinks=False,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
src_dir = os.path.join(tmp_dir, url)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
shutil.copytree(src_dir, target_dir)
|
| 50 |
+
|
| 51 |
+
shutil.rmtree(tmp_dir)
|
| 52 |
|
| 53 |
+
target_dir = "JarvisIR/checkpoints/agent_tools"
|
| 54 |
+
if not os.path.exists(target_dir):
|
| 55 |
+
download_tools_ckpts(target_dir, "agent_tools/checkpoints")
|
| 56 |
+
|
| 57 |
+
llm_targer_dir = "JarvisIR/checkpoints/pretrained_preview"
|
| 58 |
+
if not os.path.exists(llm_targer_dir):
|
| 59 |
+
download_tools_ckpts(llm_targer_dir, "pretrained/preview")
|
| 60 |
|
| 61 |
# Model configuration
|
| 62 |
# XXX: Path to the fine-tuned LLaVA model
|
| 63 |
+
model_id = llm_targer_dir
|
| 64 |
|
| 65 |
# Available image restoration tasks and their corresponding models
|
| 66 |
all_tasks = " {denoise: [scunet, restormer], lighten: [retinexformer_fivek, hvicidnet, lightdiff], \
|
|
|
|
| 96 |
print("Loading LLM model...")
|
| 97 |
|
| 98 |
# Initialize the image restoration toolkit
|
| 99 |
+
from agent_tools import RestorationToolkit
|
| 100 |
tool_engine = RestorationToolkit(score_weight=[0,0,0,0,0])
|
| 101 |
# Load the LLaVA model in half precision to reduce memory usage
|
| 102 |
model = LlavaForConditionalGeneration.from_pretrained(
|
| 103 |
model_id,
|
|
|
|
| 104 |
torch_dtype=torch.float16,
|
| 105 |
+
device_map="auto",
|
| 106 |
low_cpu_mem_usage=True
|
| 107 |
)
|
| 108 |
processor = AutoProcessor.from_pretrained(model_id)
|
|
|
|
| 221 |
return output_path
|
| 222 |
return processed_image_path
|
| 223 |
|
|
|
|
| 224 |
def get_llm_response_streaming(image_path):
|
| 225 |
"""
|
| 226 |
Get streaming response from LLM for image analysis
|
|
|
|
| 258 |
|
| 259 |
return streamer
|
| 260 |
|
| 261 |
+
|
| 262 |
def process_image_with_tools(image_path, models, original_size):
|
| 263 |
"""
|
| 264 |
Process image using the tool engine and restore to original size
|
|
|
|
| 284 |
final_result = resize_image_to_original(res['output_path'], original_size)
|
| 285 |
|
| 286 |
return final_result
|
| 287 |
+
@spaces.GPU(duration=150)
|
| 288 |
def process_full_pipeline(image):
|
| 289 |
"""
|
| 290 |
Main processing pipeline with streaming UI updates
|