vithacocf commited on
Commit
d3ab1b2
·
verified ·
1 Parent(s): 8785d5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -50
app.py CHANGED
@@ -1,53 +1,3 @@
1
- # Code anh Thang
2
- # import gradio as gr
3
- # from transformers import AutoProcessor, AutoModelForVision2Seq
4
- # from PIL import Image
5
- # import torch
6
-
7
- # device = "cuda" if torch.cuda.is_available() else "cpu"
8
- # torch.cuda.empty_cache()
9
-
10
- # model_id = "prithivMLmods/Camel-Doc-OCR-062825"
11
- # processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
12
- # model = AutoModelForVision2Seq.from_pretrained(
13
- # model_id,
14
- # torch_dtype=torch.float16 if device == "cuda" else torch.float32,
15
- # trust_remote_code=True
16
- # ).to(device)
17
-
18
- # def predict(image, prompt=None):
19
- # image = image.convert("RGB")
20
-
21
- # # Cực kỳ quan trọng: text="" bắt buộc phải có
22
- # inputs = processor(images=image, text=prompt, return_tensors="pt").to(device)
23
- # # In debug để kiểm tra input_ids
24
- # print(">>> input_ids shape:", inputs.input_ids.shape)
25
- # generated_ids = model.generate(
26
- # **inputs,
27
- # max_new_tokens=512,
28
- # do_sample=False,
29
- # use_cache=False, # ✅ Thêm dòng này để fix lỗi cache_position
30
- # eos_token_id=processor.tokenizer.eos_token_id,
31
- # pad_token_id=processor.tokenizer.pad_token_id
32
- # )
33
-
34
- # result = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
35
- # return result
36
-
37
- # demo = gr.Interface(
38
- # fn=predict,
39
- # inputs=[
40
- # gr.Image(type="pil", label="Tải ảnh tài liệu lên"),
41
- # gr.Textbox(label="Gợi ý (tuỳ chọn)", placeholder="VD: Trích số hóa đơn")
42
- # ],
43
- # outputs="text",
44
- # title="Camel-Doc OCR - Trích xuất văn bản từ ảnh"
45
- # )
46
-
47
- # if __name__ == "__main__":
48
- # demo.launch()
49
-
50
- # Code fix
51
  import os
52
  import json
53
  import re
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import json
3
  import re