| import easyocr |
| import numpy as np |
| import streamlit as st |
| from PIL import Image |
|
|
| st.set_page_config(layout="wide") |
|
|
| def write_to_txt(file_path, data): |
| all_text = "" |
| with open(file_path, 'w') as file: |
| for entry in data: |
| _, text, _ = entry |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| file.write(f"{text}\n") |
| all_text += text + "\n" |
| return all_text |
|
|
| def main(): |
| st.write("Hello world!") |
| with st.sidebar: |
| st.write("Hello sidebar!") |
| f = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"]) |
| |
| if f is not None: |
| |
| img = np.array(Image.open(f)) |
| |
| reader = easyocr.Reader(["en"]) |
| out = reader.readtext(img) |
| col1, col2 = st.columns(2) |
| with col1: |
| st.image(img, width=300) |
| |
| txt = write_to_txt("out.txt", out) |
| with col2: |
| st.write("Found text:") |
| st.markdown(txt) |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| if __name__ == "__main__": |
| main() |
|
|