Spaces:
Running
on
Zero
Running
on
Zero
Update src/app.py
Browse files- src/app.py +22 -4
src/app.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1 |
# Code developed by: Ruslan Magana Vsevolodovna
|
|
|
|
|
2 |
from collections.abc import Iterator
|
3 |
from datetime import datetime
|
4 |
from pathlib import Path
|
@@ -59,8 +61,13 @@ text_tokenizer.use_default_system_prompt = False
|
|
59 |
vision_model_path = "ibm-granite/granite-vision-3.1-2b-preview"
|
60 |
vision_processor = LlavaNextProcessor.from_pretrained(vision_model_path, use_fast=True)
|
61 |
vision_model = LlavaNextForConditionalGeneration.from_pretrained(
|
62 |
-
vision_model_path,
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
|
66 |
@spaces.GPU
|
@@ -316,6 +323,13 @@ with gr.Blocks(fill_height=True, css_paths=css_file_path, head_paths=head_file_p
|
|
316 |
)
|
317 |
|
318 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
319 |
gr.Examples(
|
320 |
examples=[
|
321 |
["Explain the concept of quantum computing to someone with no background in physics or computer science.", None],
|
@@ -375,7 +389,9 @@ The Pair class is a simple data structure that stores two integers.
|
|
375 |
|
376 |
The main method creates an array of integers, initializes the difference value, and calls the findPairs method to find all pairs in the array. Finally, the code iterates over the list of pairs and prints each pair to the console.""" , None # noqa: E501
|
377 |
],
|
378 |
-
["What is in this image?",
|
|
|
|
|
379 |
],
|
380 |
inputs=[text_input, image_input],
|
381 |
example_labels=[
|
@@ -385,7 +401,9 @@ The main method creates an array of integers, initializes the difference value,
|
|
385 |
"Boosting productivity habits",
|
386 |
"Explain and document your code",
|
387 |
"Generate Java Code",
|
388 |
-
"Vision Example: What is in this image?"
|
|
|
|
|
389 |
],
|
390 |
cache_examples=False,
|
391 |
)
|
|
|
1 |
# Code developed by: Ruslan Magana Vsevolodovna
|
2 |
+
"""Template Demo for IBM Granite Hugging Face spaces."""
|
3 |
+
|
4 |
from collections.abc import Iterator
|
5 |
from datetime import datetime
|
6 |
from pathlib import Path
|
|
|
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=torch.float16,
|
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
|
|
|
323 |
)
|
324 |
|
325 |
|
326 |
+
image_examples_dir = Path(__file__).parent / "image_examples" # Create a folder 'image_examples' in the same directory as app.py and put images there
|
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'
|
330 |
+
str(image_examples_dir / "horse.jpg") # Replace "horse.jpg" with actual image file names in 'image_examples'
|
331 |
+
]
|
332 |
+
|
333 |
gr.Examples(
|
334 |
examples=[
|
335 |
["Explain the concept of quantum computing to someone with no background in physics or computer science.", None],
|
|
|
389 |
|
390 |
The main method creates an array of integers, initializes the difference value, and calls the findPairs method to find all pairs in the array. Finally, the code iterates over the list of pairs and prints each pair to the console.""" , None # noqa: E501
|
391 |
],
|
392 |
+
["What is in this image?", image_examples[0]], # Vision example using local image
|
393 |
+
["Describe this image in detail", image_examples[1]], # Vision example using local image
|
394 |
+
["Identify the object in the image", image_examples[2]], # Vision example using local image
|
395 |
],
|
396 |
inputs=[text_input, image_input],
|
397 |
example_labels=[
|
|
|
401 |
"Boosting productivity habits",
|
402 |
"Explain and document your code",
|
403 |
"Generate Java Code",
|
404 |
+
"Vision Example 1: What is in this image?",
|
405 |
+
"Vision Example 2: Describe this image",
|
406 |
+
"Vision Example 3: Identify object",
|
407 |
],
|
408 |
cache_examples=False,
|
409 |
)
|