Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ app.py
|
|
3 |
|
4 |
A unified Gradio chat application for Multimodal OCR Granite Vision.
|
5 |
Commands (enter these as a prefix in the text input):
|
6 |
-
- @rag: For retrieval‐augmented generation (e.g.
|
7 |
- @granite: For image understanding.
|
8 |
- @video-infer: For video understanding (video is downsampled into frames).
|
9 |
|
@@ -14,13 +14,13 @@ import os
|
|
14 |
import time
|
15 |
import uuid
|
16 |
import random
|
|
|
17 |
import logging
|
18 |
from threading import Thread
|
19 |
from pathlib import Path
|
20 |
from datetime import datetime, timezone
|
21 |
|
22 |
import torch
|
23 |
-
import spaces
|
24 |
import numpy as np
|
25 |
import cv2
|
26 |
from PIL import Image
|
@@ -165,7 +165,8 @@ def load_granite_model():
|
|
165 |
global granite_processor, granite_model
|
166 |
if granite_processor is None or granite_model is None:
|
167 |
granite_processor = AutoProcessor.from_pretrained(GRANITE_MODEL_ID)
|
168 |
-
|
|
|
169 |
return granite_processor, granite_model
|
170 |
|
171 |
def create_single_turn(image, text):
|
@@ -328,4 +329,4 @@ demo = gr.ChatInterface(
|
|
328 |
)
|
329 |
|
330 |
if __name__ == "__main__":
|
331 |
-
demo.queue(max_size=20).launch()
|
|
|
3 |
|
4 |
A unified Gradio chat application for Multimodal OCR Granite Vision.
|
5 |
Commands (enter these as a prefix in the text input):
|
6 |
+
- @rag: For retrieval‐augmented generation (e.g. PDFs or text-based queries).
|
7 |
- @granite: For image understanding.
|
8 |
- @video-infer: For video understanding (video is downsampled into frames).
|
9 |
|
|
|
14 |
import time
|
15 |
import uuid
|
16 |
import random
|
17 |
+
import spaces
|
18 |
import logging
|
19 |
from threading import Thread
|
20 |
from pathlib import Path
|
21 |
from datetime import datetime, timezone
|
22 |
|
23 |
import torch
|
|
|
24 |
import numpy as np
|
25 |
import cv2
|
26 |
from PIL import Image
|
|
|
165 |
global granite_processor, granite_model
|
166 |
if granite_processor is None or granite_model is None:
|
167 |
granite_processor = AutoProcessor.from_pretrained(GRANITE_MODEL_ID)
|
168 |
+
# Remove the .to(device) call to avoid moving a model already offloaded via accelerate.
|
169 |
+
granite_model = AutoModelForVision2Seq.from_pretrained(GRANITE_MODEL_ID, device_map="auto")
|
170 |
return granite_processor, granite_model
|
171 |
|
172 |
def create_single_turn(image, text):
|
|
|
329 |
)
|
330 |
|
331 |
if __name__ == "__main__":
|
332 |
+
demo.queue(max_size=20).launch()
|