Chhagan Singh commited on
Commit
9cf81f9
Β·
1 Parent(s): bd7f4cb

Fix: load OCR model as LoRA adapter on Qwen2-VL-2B-Instruct base using PEFT

Browse files
Files changed (2) hide show
  1. app.py +20 -11
  2. issuelog +0 -0
app.py CHANGED
@@ -1,8 +1,8 @@
1
  """
2
  Chhagan DocVL AI - Document Intelligence Demo
3
  Models:
4
- - Chhagan005/Chhagan-DocVL-Qwen3 (Qwen3-VL architecture)
5
- - Chhagan005/Chhagan_ML-VL-OCR-v1 (Qwen2-VL architecture)
6
  Based on: Qwen3-VL-Outpost reference pattern
7
  """
8
  import os
@@ -14,6 +14,7 @@ import gradio as gr
14
  import spaces
15
  import torch
16
  from PIL import Image
 
17
 
18
  from transformers import (
19
  Qwen3VLForConditionalGeneration,
@@ -26,7 +27,8 @@ logging.getLogger("transformers").setLevel(logging.ERROR)
26
 
27
  # ---------- CONFIG ----------
28
  MODEL_DOCVL = "Chhagan005/Chhagan-DocVL-Qwen3"
29
- MODEL_OCR = "Chhagan005/Chhagan_ML-VL-OCR-v1"
 
30
  HF_TOKEN = os.getenv("HF_TOKEN")
31
 
32
  MAX_MAX_NEW_TOKENS = 4096
@@ -35,7 +37,7 @@ DEFAULT_MAX_NEW_TOKENS = 1024
35
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
36
  print("Using device:", device)
37
 
38
- # ---------- LOAD MODEL 1: DocVL (Qwen3-VL) ----------
39
  print("=" * 60)
40
  print("πŸš€ Loading Chhagan-DocVL-Qwen3 ...")
41
  print("=" * 60)
@@ -48,18 +50,25 @@ model_docvl = Qwen3VLForConditionalGeneration.from_pretrained(
48
  ).to(device).eval()
49
  print(" βœ… Chhagan-DocVL-Qwen3 loaded")
50
 
51
- # ---------- LOAD MODEL 2: OCR-v1 (Qwen2-VL) ----------
52
  print("=" * 60)
53
- print("πŸš€ Loading Chhagan_ML-VL-OCR-v1 ...")
54
  print("=" * 60)
55
 
56
  processor_ocr = AutoProcessor.from_pretrained(
57
- MODEL_OCR, trust_remote_code=True, token=HF_TOKEN,
58
  )
59
- model_ocr = Qwen2VLForConditionalGeneration.from_pretrained(
60
- MODEL_OCR, trust_remote_code=True, torch_dtype=torch.float16, token=HF_TOKEN,
61
- ).to(device).eval()
62
- print(" βœ… Chhagan_ML-VL-OCR-v1 loaded")
 
 
 
 
 
 
 
63
  print("=" * 60)
64
 
65
 
 
1
  """
2
  Chhagan DocVL AI - Document Intelligence Demo
3
  Models:
4
+ - Chhagan005/Chhagan-DocVL-Qwen3 (Qwen3-VL LoRA adapter)
5
+ - Chhagan005/Chhagan_ML-VL-OCR-v1 (Qwen2-VL LoRA adapter on Qwen/Qwen2-VL-2B-Instruct)
6
  Based on: Qwen3-VL-Outpost reference pattern
7
  """
8
  import os
 
14
  import spaces
15
  import torch
16
  from PIL import Image
17
+ from peft import PeftModel
18
 
19
  from transformers import (
20
  Qwen3VLForConditionalGeneration,
 
27
 
28
  # ---------- CONFIG ----------
29
  MODEL_DOCVL = "Chhagan005/Chhagan-DocVL-Qwen3"
30
+ MODEL_OCR_ADAPTER = "Chhagan005/Chhagan_ML-VL-OCR-v1"
31
+ MODEL_OCR_BASE = "Qwen/Qwen2-VL-2B-Instruct"
32
  HF_TOKEN = os.getenv("HF_TOKEN")
33
 
34
  MAX_MAX_NEW_TOKENS = 4096
 
37
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
38
  print("Using device:", device)
39
 
40
+ # ---------- LOAD MODEL 1: DocVL (Qwen3-VL LoRA) ----------
41
  print("=" * 60)
42
  print("πŸš€ Loading Chhagan-DocVL-Qwen3 ...")
43
  print("=" * 60)
 
50
  ).to(device).eval()
51
  print(" βœ… Chhagan-DocVL-Qwen3 loaded")
52
 
53
+ # ---------- LOAD MODEL 2: OCR-v1 (Qwen2-VL + LoRA adapter) ----------
54
  print("=" * 60)
55
+ print("πŸš€ Loading Chhagan_ML-VL-OCR-v1 (base + LoRA) ...")
56
  print("=" * 60)
57
 
58
  processor_ocr = AutoProcessor.from_pretrained(
59
+ MODEL_OCR_BASE, trust_remote_code=True, token=HF_TOKEN,
60
  )
61
+ print(" βœ… OCR Processor loaded (from base)")
62
+
63
+ base_model_ocr = Qwen2VLForConditionalGeneration.from_pretrained(
64
+ MODEL_OCR_BASE, trust_remote_code=True, torch_dtype=torch.float16, token=HF_TOKEN,
65
+ ).to(device)
66
+ print(" βœ… OCR Base model loaded")
67
+
68
+ model_ocr = PeftModel.from_pretrained(
69
+ base_model_ocr, MODEL_OCR_ADAPTER, token=HF_TOKEN,
70
+ ).eval()
71
+ print(" βœ… OCR LoRA adapter applied")
72
  print("=" * 60)
73
 
74
 
issuelog CHANGED
The diff for this file is too large to render. See raw diff