Divyansh12 commited on
Commit
0cc2c1c
·
verified ·
1 Parent(s): 2dd690c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  from transformers import AutoModel, AutoTokenizer
3
  import streamlit as st
4
  from PIL import Image
@@ -21,7 +20,7 @@ def load_model(model_name):
21
  return model, tokenizer
22
 
23
  if "model" not in st.session_state or "tokenizer" not in st.session_state:
24
- model, tokenizer = load_model("OCR for English or Hindi (CPU)")
25
  st.session_state.update({"model": model, "tokenizer": tokenizer})
26
 
27
  # Function to run the GOT model for multilingual OCR
@@ -42,8 +41,8 @@ def highlight_text(text, search_term):
42
  return re.sub(re.escape(search_term), lambda m: f'<span style="background-color: red;">{m.group()}</span>', text, flags=re.IGNORECASE) if search_term else text
43
 
44
  # Streamlit App
45
- st.title(":blue[Object character recognition Application]")
46
- st.write("Give your Image")
47
 
48
  # Create two columns
49
  col1, col2 = st.columns(2)
@@ -59,7 +58,7 @@ with col1:
59
  with col2:
60
  model_option = st.selectbox("Select Model", ["OCR on CPU", "OCR on GPU"])
61
 
62
- if st.button("DO OCR "):
63
  if uploaded_image:
64
  with st.spinner("Processing..."):
65
  model, tokenizer = load_model(model_option)
@@ -74,5 +73,4 @@ with col2:
74
  # Display the extracted text if it exists in session state
75
  if "extracted_text" in st.session_state:
76
  search_term = st.text_input("Enter a word or phrase to highlight:")
77
- st.subheader("Extracted Text:")
78
- st.markdown(f'<div style="white-space: pre-wrap;">{highlight_text(st.session_state["extracted_text"], search_term)}</div>', unsafe_allow_html=True)
 
 
1
  from transformers import AutoModel, AutoTokenizer
2
  import streamlit as st
3
  from PIL import Image
 
20
  return model, tokenizer
21
 
22
  if "model" not in st.session_state or "tokenizer" not in st.session_state:
23
+ model, tokenizer = load_model("OCR on CPU")
24
  st.session_state.update({"model": model, "tokenizer": tokenizer})
25
 
26
  # Function to run the GOT model for multilingual OCR
 
41
  return re.sub(re.escape(search_term), lambda m: f'<span style="background-color: red;">{m.group()}</span>', text, flags=re.IGNORECASE) if search_term else text
42
 
43
  # Streamlit App
44
+ st.title("GOT-OCR Multilingual Demo")
45
+ st.write("Upload an image for OCR")
46
 
47
  # Create two columns
48
  col1, col2 = st.columns(2)
 
58
  with col2:
59
  model_option = st.selectbox("Select Model", ["OCR on CPU", "OCR on GPU"])
60
 
61
+ if st.button("Run OCR"):
62
  if uploaded_image:
63
  with st.spinner("Processing..."):
64
  model, tokenizer = load_model(model_option)
 
73
  # Display the extracted text if it exists in session state
74
  if "extracted_text" in st.session_state:
75
  search_term = st.text_input("Enter a word or phrase to highlight:")
76
+ st.subheader("Extracted Text:")