VideoGenerator / app.py
Devticks's picture
Update app.py
3ecbc8c verified
raw
history blame
2.02 kB
# from flask import Flask, request, jsonify
# from handler import EndpointHandler
# app = Flask(__name__)
# handler = EndpointHandler()
# @app.route('/process_image', methods=['POST'])
# def process_image():
# data = request.json
# if data is None:
# return jsonify({'error': 'No JSON data received'}), 400
# try:
# result_image = handler(data)
# except Exception as e:
# return jsonify({'error': str(e)}), 500
# # Convert PIL image to base64 string
# buffered = BytesIO()
# result_image.save(buffered, format="JPEG")
# result_image_str = base64.b64encode(buffered.getvalue()).decode()
# return jsonify({'result_image': result_image_str})
# if __name__ == '__main__':
# app.run(debug=False,port=8001)
import easyocr as ocr #OCR
import streamlit as st #Web App
from PIL import Image #Image Processing
import numpy as np #Image Processing
#title
st.title("Easy OCR - Extract Text from Images")
#subtitle
st.markdown("## Optical Character Recognition - Using `easyocr`, `streamlit` - hosted on πŸ€— Spaces")
st.markdown("Link to the app - [image-to-text-app on πŸ€— Spaces](https://huggingface.co/spaces/Amrrs/image-to-text-app)")
#image uploader
image = st.file_uploader(label = "Upload your image here",type=['png','jpg','jpeg'])
@st.cache
def load_model():
reader = ocr.Reader(['en'],model_storage_directory='.')
return reader
reader = load_model() #load model
if image is not None:
input_image = Image.open(image) #read image
st.image(input_image) #display image
with st.spinner("πŸ€– AI is at Work! "):
result = reader.readtext(np.array(input_image))
result_text = [] #empty list for results
for text in result:
result_text.append(text[1])
st.write(result_text)
#st.success("Here you go!")
st.balloons()
else:
st.write("Upload an Image")
st.caption("Made with ❀️ by @1littlecoder. Credits to πŸ€— Spaces for Hosting this ")