Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import streamlit as st
|
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
import io
|
6 |
-
from transformers import AutoProcessor,
|
7 |
from peft import PeftModel
|
8 |
|
9 |
# Page config
|
@@ -21,12 +21,23 @@ st.markdown("Upload an image to analyze it for possible deepfake manipulation")
|
|
21 |
def load_model():
|
22 |
"""Load model and processor (cached to avoid reloading)"""
|
23 |
# Load base model
|
24 |
-
base_model_id = "unsloth/llama-3.2-11b-vision-instruct"
|
25 |
processor = AutoProcessor.from_pretrained(base_model_id)
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
base_model_id,
|
28 |
device_map="auto",
|
29 |
-
torch_dtype=torch.float16
|
|
|
30 |
)
|
31 |
|
32 |
# Load adapter
|
|
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
import io
|
6 |
+
from transformers import AutoProcessor, BitsAndBytesConfig, MllamaForCausalLM
|
7 |
from peft import PeftModel
|
8 |
|
9 |
# Page config
|
|
|
21 |
def load_model():
|
22 |
"""Load model and processor (cached to avoid reloading)"""
|
23 |
# Load base model
|
24 |
+
base_model_id = "unsloth/llama-3.2-11b-vision-instruct-unsloth-bnb-4bit"
|
25 |
processor = AutoProcessor.from_pretrained(base_model_id)
|
26 |
+
|
27 |
+
# Configure 4-bit quantization
|
28 |
+
quantization_config = BitsAndBytesConfig(
|
29 |
+
load_in_4bit=True,
|
30 |
+
bnb_4bit_compute_dtype=torch.float16,
|
31 |
+
bnb_4bit_quant_type="nf4",
|
32 |
+
bnb_4bit_use_double_quant=True
|
33 |
+
)
|
34 |
+
|
35 |
+
# Use the specific model class MllamaForCausalLM instead of AutoModelForCausalLM
|
36 |
+
model = MllamaForCausalLM.from_pretrained(
|
37 |
base_model_id,
|
38 |
device_map="auto",
|
39 |
+
torch_dtype=torch.float16,
|
40 |
+
quantization_config=quantization_config
|
41 |
)
|
42 |
|
43 |
# Load adapter
|