Spaces:
Running
on
Zero
Running
on
Zero
Update src/app.py
Browse files- src/app.py +15 -7
src/app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
# Code developed by: Ruslan Magana Vsevolodovna
|
2 |
"""Template Demo for IBM Granite Hugging Face spaces."""
|
3 |
|
4 |
from collections.abc import Iterator
|
@@ -60,15 +59,24 @@ text_tokenizer.use_default_system_prompt = False
|
|
60 |
# Vision model loading
|
61 |
vision_model_path = "ibm-granite/granite-vision-3.1-2b-preview"
|
62 |
vision_processor = LlavaNextProcessor.from_pretrained(vision_model_path, use_fast=True)
|
|
|
|
|
63 |
vision_model = LlavaNextForConditionalGeneration.from_pretrained(
|
64 |
vision_model_path,
|
65 |
-
torch_dtype=
|
66 |
-
device_map="auto"
|
67 |
-
low_cpu_mem_usage=True,
|
68 |
-
force_download=True, # Added force_download to ensure fresh download
|
69 |
-
revision="main" # Added revision to specify main branch (if needed)
|
70 |
)
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
@spaces.GPU
|
74 |
def generate(
|
@@ -323,7 +331,7 @@ with gr.Blocks(fill_height=True, css_paths=css_file_path, head_paths=head_file_p
|
|
323 |
)
|
324 |
|
325 |
|
326 |
-
image_examples_dir = Path(__file__).parent / "
|
327 |
image_examples = [
|
328 |
str(image_examples_dir / "cat.jpg"), # Replace "cat.jpg" with actual image file names in 'image_examples'
|
329 |
str(image_examples_dir / "dog.jpg"), # Replace "dog.jpg" with actual image file names in 'image_examples'
|
|
|
|
|
1 |
"""Template Demo for IBM Granite Hugging Face spaces."""
|
2 |
|
3 |
from collections.abc import Iterator
|
|
|
59 |
# Vision model loading
|
60 |
vision_model_path = "ibm-granite/granite-vision-3.1-2b-preview"
|
61 |
vision_processor = LlavaNextProcessor.from_pretrained(vision_model_path, use_fast=True)
|
62 |
+
|
63 |
+
# Option 1: Use the default settings (like the original demo)
|
64 |
vision_model = LlavaNextForConditionalGeneration.from_pretrained(
|
65 |
vision_model_path,
|
66 |
+
torch_dtype="auto",
|
67 |
+
device_map="auto"
|
|
|
|
|
|
|
68 |
)
|
69 |
|
70 |
+
# --- OR ---
|
71 |
+
|
72 |
+
# Option 2: Use torch.float16 but ensure the custom model code is trusted
|
73 |
+
# vision_model = LlavaNextForConditionalGeneration.from_pretrained(
|
74 |
+
# vision_model_path,
|
75 |
+
# torch_dtype=torch.float16,
|
76 |
+
# device_map="auto",
|
77 |
+
# trust_remote_code=True
|
78 |
+
# )
|
79 |
+
|
80 |
|
81 |
@spaces.GPU
|
82 |
def generate(
|
|
|
331 |
)
|
332 |
|
333 |
|
334 |
+
image_examples_dir = Path(__file__).parent / "themes" # Create a folder 'themes' in the same directory as app.py and put images there
|
335 |
image_examples = [
|
336 |
str(image_examples_dir / "cat.jpg"), # Replace "cat.jpg" with actual image file names in 'image_examples'
|
337 |
str(image_examples_dir / "dog.jpg"), # Replace "dog.jpg" with actual image file names in 'image_examples'
|