Aekanun commited on
Commit
59ee2e8
1 Parent(s): 76059b0

fixed app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
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
- hub_model_path = "Aekanun/thai-handwriting-llm"
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 from Hub
45
- print("กำลังโหลดโมเดลจาก Hub...")
46
- model = AutoModelForVision2Seq.from_pretrained(
47
- hub_model_path,
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: