Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,17 @@
|
|
1 |
-
import
|
2 |
from transformers import AutoProcessor, AutoModelForCausalLM
|
|
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
|
6 |
-
# Load the
|
|
|
7 |
model_name = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
8 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
|
10 |
-
processor
|
11 |
-
|
|
|
12 |
|
13 |
# Function to process image and text prompt
|
14 |
def process_image(image, prompt="<ocr>"):
|
|
|
1 |
+
import os
|
2 |
from transformers import AutoProcessor, AutoModelForCausalLM
|
3 |
+
import gradio as gr
|
4 |
import torch
|
5 |
from PIL import Image
|
6 |
|
7 |
+
# Load the Hugging Face token from environment variables
|
8 |
+
hf_token = os.getenv("HF_AUTH_TOKEN")
|
9 |
model_name = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
|
12 |
+
# Load the model and processor with authentication
|
13 |
+
processor = AutoProcessor.from_pretrained(model_name, use_auth_token=hf_token, trust_remote_code=True)
|
14 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=hf_token, torch_dtype=torch.float16, trust_remote_code=True).to(device)
|
15 |
|
16 |
# Function to process image and text prompt
|
17 |
def process_image(image, prompt="<ocr>"):
|