Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,7 @@ from transformers import BitsAndBytesConfig
|
|
20 |
import torch
|
21 |
from huggingface_hub import InferenceClient
|
22 |
from transformers import AutoTokenizer
|
|
|
23 |
import spaces
|
24 |
IS_SPACES_ZERO = os.environ.get("SPACES_ZERO_GPU", "0") == "1"
|
25 |
IS_SPACE = os.environ.get("SPACE_ID", None) is not None
|
@@ -43,11 +44,14 @@ quantization_config = BitsAndBytesConfig(
|
|
43 |
|
44 |
# Load the tokenizer associated with your 'MODEL_ID'
|
45 |
tokenizer_image_to_text = AutoTokenizer.from_pretrained(MODEL_ID)
|
|
|
|
|
46 |
# Load models only once
|
47 |
processor = AutoProcessor.from_pretrained(MODEL_ID)
|
48 |
model = LlavaForConditionalGeneration.from_pretrained(MODEL_ID, quantization_config=quantization_config, device_map="auto")
|
49 |
# Pass the tokenizer explicitly to the pipeline
|
50 |
-
|
|
|
51 |
# Initialize the text generation pipeline
|
52 |
pipe_text = pipeline("text-generation", model=TEXT_MODEL_ID, model_kwargs={"quantization_config": quantization_config})
|
53 |
|
|
|
20 |
import torch
|
21 |
from huggingface_hub import InferenceClient
|
22 |
from transformers import AutoTokenizer
|
23 |
+
from transformers import AutoImageProcessor
|
24 |
import spaces
|
25 |
IS_SPACES_ZERO = os.environ.get("SPACES_ZERO_GPU", "0") == "1"
|
26 |
IS_SPACE = os.environ.get("SPACE_ID", None) is not None
|
|
|
44 |
|
45 |
# Load the tokenizer associated with your 'MODEL_ID'
|
46 |
tokenizer_image_to_text = AutoTokenizer.from_pretrained(MODEL_ID)
|
47 |
+
# Load the image processor associated with your 'MODEL_ID'
|
48 |
+
image_processor = AutoImageProcessor.from_pretrained(MODEL_ID)
|
49 |
# Load models only once
|
50 |
processor = AutoProcessor.from_pretrained(MODEL_ID)
|
51 |
model = LlavaForConditionalGeneration.from_pretrained(MODEL_ID, quantization_config=quantization_config, device_map="auto")
|
52 |
# Pass the tokenizer explicitly to the pipeline
|
53 |
+
# Pass the image processor explicitly to the pipeline
|
54 |
+
pipe_image_to_text = pipeline("image-to-text", model=model, tokenizer=tokenizer_image_to_text, image_processor=image_processor, model_kwargs={"quantization_config": quantization_config})
|
55 |
# Initialize the text generation pipeline
|
56 |
pipe_text = pipeline("text-generation", model=TEXT_MODEL_ID, model_kwargs={"quantization_config": quantization_config})
|
57 |
|