akhil-vaidya commited on
Commit
1fedf30
1 Parent(s): 1729495

caching model

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -7,8 +7,8 @@ import torch
7
  from torchvision import io
8
  from typing import Dict
9
  import base64
10
- import random
11
 
 
12
  def init_model():
13
  tokenizer = AutoTokenizer.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True)
14
  model = AutoModel.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True, use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
@@ -71,6 +71,7 @@ def get_quen_op(image_file, model, processor):
71
  except Exception as e:
72
  return f"An error occurred: {str(e)}"
73
 
 
74
  def init_llama():
75
  model_id = "meta-llama/Llama-3.2-11B-Vision-Instruct"
76
 
@@ -105,12 +106,10 @@ def get_text(image_file, model, tokenizer):
105
  res = model.chat(tokenizer, image_file, ocr_type='ocr')
106
  return res
107
 
108
- st.title("Image - Text OCR")
109
  st.write("Upload an image for OCR")
110
 
111
- MODEL, PROCESSOR = init_llama()
112
- random_value = random.randint(0, 100)
113
- st.write(f"Model loaded: build number - {random_value}")
114
 
115
  image_file = st.file_uploader("Upload Image", type=['jpg', 'png', 'jpeg'])
116
 
@@ -125,10 +124,10 @@ if image_file:
125
 
126
  # model, tokenizer = init_gpu_model()
127
  # model, tokenizer = init_model()
128
- # text = get_text(image_file, model, tokenizer)
129
 
130
  # model, processor = init_llama()
131
- text = get_llama_op(image_file, MODEL, PROCESSOR)
132
 
133
  # model, processor = init_qwen_model()
134
  # text = get_quen_op(image_file, model, processor)
 
7
  from torchvision import io
8
  from typing import Dict
9
  import base64
 
10
 
11
+ @st.cache_resource
12
  def init_model():
13
  tokenizer = AutoTokenizer.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True)
14
  model = AutoModel.from_pretrained('srimanth-d/GOT_CPU', trust_remote_code=True, use_safetensors=True, pad_token_id=tokenizer.eos_token_id)
 
71
  except Exception as e:
72
  return f"An error occurred: {str(e)}"
73
 
74
+ @st.cache_resource
75
  def init_llama():
76
  model_id = "meta-llama/Llama-3.2-11B-Vision-Instruct"
77
 
 
106
  res = model.chat(tokenizer, image_file, ocr_type='ocr')
107
  return res
108
 
109
+ st.title("Image - Text OCR (General OCR Theory - GOT)")
110
  st.write("Upload an image for OCR")
111
 
112
+ MODEL, PROCESSOR = init_model()
 
 
113
 
114
  image_file = st.file_uploader("Upload Image", type=['jpg', 'png', 'jpeg'])
115
 
 
124
 
125
  # model, tokenizer = init_gpu_model()
126
  # model, tokenizer = init_model()
127
+ text = get_text(image_file, MODEL, PROCESSOR)
128
 
129
  # model, processor = init_llama()
130
+ # text = get_llama_op(image_file, MODEL, PROCESSOR)
131
 
132
  # model, processor = init_qwen_model()
133
  # text = get_quen_op(image_file, model, processor)