retromarz commited on
Commit
f907e73
·
verified ·
1 Parent(s): cfee9b9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -15,15 +15,14 @@ logger = logging.getLogger(__name__)
15
  # Define output JSON file path
16
  OUTPUT_JSON_PATH = "captions.json"
17
 
18
- # Load the model and processor with memory optimizations
19
  MODEL_PATH = "fancyfeast/llama-joycaption-beta-one-hf-llava"
20
  try:
21
  processor = AutoProcessor.from_pretrained(MODEL_PATH)
22
  model = LlavaForConditionalGeneration.from_pretrained(
23
  MODEL_PATH,
24
  torch_dtype=torch.float32, # CPU-compatible dtype
25
- low_cpu_mem_usage=True, # Minimize memory usage
26
- load_in_4bit=True # Enable 4-bit quantization
27
  ).to("cpu")
28
  model.eval()
29
  logger.info("Model and processor loaded successfully.")
@@ -71,7 +70,7 @@ def generate_caption(input_image: Image.Image, caption_type: str = "descriptive"
71
 
72
  try:
73
  # Resize image to reduce memory usage
74
- input_image = input_image.resize((256, 256)) # Smaller resolution
75
 
76
  # Prepare the prompt
77
  prompt = f"Write a {caption_length} {caption_type} caption for this image."
 
15
  # Define output JSON file path
16
  OUTPUT_JSON_PATH = "captions.json"
17
 
18
+ # Load the model and processor
19
  MODEL_PATH = "fancyfeast/llama-joycaption-beta-one-hf-llava"
20
  try:
21
  processor = AutoProcessor.from_pretrained(MODEL_PATH)
22
  model = LlavaForConditionalGeneration.from_pretrained(
23
  MODEL_PATH,
24
  torch_dtype=torch.float32, # CPU-compatible dtype
25
+ low_cpu_mem_usage=True # Minimize memory usage
 
26
  ).to("cpu")
27
  model.eval()
28
  logger.info("Model and processor loaded successfully.")
 
70
 
71
  try:
72
  # Resize image to reduce memory usage
73
+ input_image = input_image.resize((256, 256)) # Small resolution
74
 
75
  # Prepare the prompt
76
  prompt = f"Write a {caption_length} {caption_type} caption for this image."