Solo448 commited on
Commit
84534f7
·
verified ·
1 Parent(s): 23ba17d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -17,7 +17,8 @@ import tiktoken
17
  import verovio
18
  model_name = "ucaslcl/GOT-OCR2_0"
19
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
20
- model = AutoModel.from_pretrained(model_name, trust_remote_code=True, low_cpu_mem_usage=True, device_map='cuda', use_safetensors=True).eval().cuda()
 
21
 
22
  UPLOAD_FOLDER = "./uploads"
23
  RESULTS_FOLDER = "./results"
@@ -32,7 +33,8 @@ def image_to_base64(image):
32
  return base64.b64encode(buffered.getvalue()).decode()
33
 
34
  q_model_name = "Qwen/Qwen2-VL-2B-Instruct"
35
- q_model = Qwen2VLForConditionalGeneration.from_pretrained(q_model_name, torch_dtype="auto").cuda().eval()
 
36
  q_processor = AutoProcessor.from_pretrained(q_model_name, trust_remote_code=True)
37
 
38
  def get_qwen_op(image_file, model, processor):
@@ -53,7 +55,8 @@ def get_qwen_op(image_file, model, processor):
53
  }
54
  ]
55
  text_prompt = q_processor.apply_chat_template(conversation, add_generation_prompt=True)
56
- inputs = q_processor(text=[text_prompt], images=[image], padding=True, return_tensors="pt").to("cuda")
 
57
  inputs = {k: v.to(torch.float32) if torch.is_floating_point(v) else v for k, v in inputs.items()}
58
 
59
  generation_config = {
 
17
  import verovio
18
  model_name = "ucaslcl/GOT-OCR2_0"
19
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
20
+ #model = AutoModel.from_pretrained(model_name, trust_remote_code=True, low_cpu_mem_usage=True, device_map='cuda', use_safetensors=True).eval().cuda()
21
+ model = AutoModel.from_pretrained(model_name, trust_remote_code=True, low_cpu_mem_usage=True, device_map='cpu', use_safetensors=True).eval()
22
 
23
  UPLOAD_FOLDER = "./uploads"
24
  RESULTS_FOLDER = "./results"
 
33
  return base64.b64encode(buffered.getvalue()).decode()
34
 
35
  q_model_name = "Qwen/Qwen2-VL-2B-Instruct"
36
+ #q_model = Qwen2VLForConditionalGeneration.from_pretrained(q_model_name, torch_dtype="auto").cuda().eval()
37
+ q_model = Qwen2VLForConditionalGeneration.from_pretrained(q_model_name, torch_dtype="cpu").eval()
38
  q_processor = AutoProcessor.from_pretrained(q_model_name, trust_remote_code=True)
39
 
40
  def get_qwen_op(image_file, model, processor):
 
55
  }
56
  ]
57
  text_prompt = q_processor.apply_chat_template(conversation, add_generation_prompt=True)
58
+ #inputs = q_processor(text=[text_prompt], images=[image], padding=True, return_tensors="pt").to("cuda")
59
+ inputs = q_processor(text=[text_prompt], images=[image], padding=True, return_tensors="pt")
60
  inputs = {k: v.to(torch.float32) if torch.is_floating_point(v) else v for k, v in inputs.items()}
61
 
62
  generation_config = {