Spaces:
Running
on
Zero
Running
on
Zero
fixed app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import warnings
|
|
3 |
import torch
|
4 |
import gc
|
5 |
from transformers import AutoModelForVision2Seq, AutoProcessor
|
|
|
6 |
from PIL import Image
|
7 |
import gradio as gr
|
8 |
from huggingface_hub import login
|
@@ -35,21 +36,32 @@ def load_model_and_processor():
|
|
35 |
try:
|
36 |
# Model paths
|
37 |
base_model_path = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
38 |
-
|
39 |
|
40 |
# Load processor from base model
|
41 |
print("กำลังโหลด processor...")
|
42 |
processor = AutoProcessor.from_pretrained(base_model_path, use_auth_token=True)
|
43 |
|
44 |
-
# Load model
|
45 |
-
print("
|
46 |
-
|
47 |
-
|
48 |
device_map="auto",
|
49 |
torch_dtype=torch.bfloat16,
|
50 |
trust_remote_code=True,
|
51 |
use_auth_token=True
|
52 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
print("โหลดโมเดลสำเร็จ!")
|
54 |
return True
|
55 |
except Exception as e:
|
|
|
3 |
import torch
|
4 |
import gc
|
5 |
from transformers import AutoModelForVision2Seq, AutoProcessor
|
6 |
+
from peft import PeftModel
|
7 |
from PIL import Image
|
8 |
import gradio as gr
|
9 |
from huggingface_hub import login
|
|
|
36 |
try:
|
37 |
# Model paths
|
38 |
base_model_path = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
39 |
+
adapter_path = "Aekanun/thai-handwriting-llm"
|
40 |
|
41 |
# Load processor from base model
|
42 |
print("กำลังโหลด processor...")
|
43 |
processor = AutoProcessor.from_pretrained(base_model_path, use_auth_token=True)
|
44 |
|
45 |
+
# Load base model
|
46 |
+
print("กำลังโหลด base model...")
|
47 |
+
base_model = AutoModelForVision2Seq.from_pretrained(
|
48 |
+
base_model_path,
|
49 |
device_map="auto",
|
50 |
torch_dtype=torch.bfloat16,
|
51 |
trust_remote_code=True,
|
52 |
use_auth_token=True
|
53 |
)
|
54 |
+
|
55 |
+
# Load adapter
|
56 |
+
print("กำลังโหลด adapter...")
|
57 |
+
model = PeftModel.from_pretrained(
|
58 |
+
base_model,
|
59 |
+
adapter_path,
|
60 |
+
torch_dtype=torch.bfloat16,
|
61 |
+
device_map="auto",
|
62 |
+
use_auth_token=True
|
63 |
+
)
|
64 |
+
|
65 |
print("โหลดโมเดลสำเร็จ!")
|
66 |
return True
|
67 |
except Exception as e:
|