Aekanun commited on
Commit
5eb28b7
·
1 Parent(s): 1c8a6bd

fixing app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -2,7 +2,7 @@ import os
2
  import warnings
3
  import torch
4
  import gc
5
- from transformers import AutoModelForVision2Seq, AutoProcessor, BitsAndBytesConfig, AutoConfig
6
  from PIL import Image
7
  import gradio as gr
8
  from huggingface_hub import login
@@ -37,29 +37,19 @@ def load_model_and_processor():
37
  # Model paths
38
  hub_model_path = "Aekanun/thai-handwriting-llm"
39
 
40
- # BitsAndBytes config
41
- bnb_config = BitsAndBytesConfig(
42
- load_in_4bit=True,
43
- bnb_4bit_use_double_quant=True,
44
- bnb_4bit_quant_type="nf4",
45
- bnb_4bit_compute_dtype=torch.bfloat16
46
  )
47
-
48
- # Load model configuration
49
- config = AutoConfig.from_pretrained(hub_model_path, trust_remote_code=True)
50
- config.model_type = "llava" # กำหนด model_type
51
-
52
- # Load processor and model
53
- processor = AutoProcessor.from_pretrained(hub_model_path, trust_remote_code=True)
54
 
55
  print("กำลังโหลดโมเดลจาก Hub...")
56
- model = AutoModelForVision2Seq.from_pretrained(
57
  hub_model_path,
58
- config=config,
59
  device_map="auto",
60
  torch_dtype=torch.bfloat16,
61
- quantization_config=bnb_config,
62
- trust_remote_code=True
63
  )
64
  print("โหลดโมเดลสำเร็จ!")
65
 
@@ -136,4 +126,5 @@ if load_model_and_processor():
136
  if __name__ == "__main__":
137
  demo.launch()
138
  else:
139
- print("ไม่สามารถเริ่มต้นแอปพลิเคชันได้")
 
 
2
  import warnings
3
  import torch
4
  import gc
5
+ from transformers import LlavaForConditionalGeneration, LlavaProcessor
6
  from PIL import Image
7
  import gradio as gr
8
  from huggingface_hub import login
 
37
  # Model paths
38
  hub_model_path = "Aekanun/thai-handwriting-llm"
39
 
40
+ # Load processor and model directly using LLaVA classes
41
+ processor = LlavaProcessor.from_pretrained(
42
+ hub_model_path,
43
+ trust_remote_code=True
 
 
44
  )
 
 
 
 
 
 
 
45
 
46
  print("กำลังโหลดโมเดลจาก Hub...")
47
+ model = LlavaForConditionalGeneration.from_pretrained(
48
  hub_model_path,
 
49
  device_map="auto",
50
  torch_dtype=torch.bfloat16,
51
+ trust_remote_code=True,
52
+ load_in_4bit=True
53
  )
54
  print("โหลดโมเดลสำเร็จ!")
55
 
 
126
  if __name__ == "__main__":
127
  demo.launch()
128
  else:
129
+ print("ไม่สามารถเริ่มต้นแอปพลิเคชันได้")
130
+