rockerritesh's picture
Create app.py
6ef064d verified
raw
history blame
1.61 kB
import streamlit as st
import requests
def extract_text_from_image(uploaded_file):
"""Upload image to the text extraction API and return extracted text"""
files = {'image': uploaded_file}
try:
response = requests.post('https://api-1-zvvu.onrender.com/upload', files=files)
if response.status_code == 200:
return response.text
else:
return f"Error: {response.status_code} - {response.text}"
except requests.RequestException as e:
return f"Request failed: {e}"
def main():
st.title('Image Text Extraction')
# Camera input toggle
enable = st.checkbox("Enable camera")
# Camera input
picture = st.camera_input("Take a picture", disabled=not enable)
# File uploader
uploaded_file = st.file_uploader("Or upload an image...", type=['png', 'jpg', 'jpeg'])
# Determine which image to use
image_to_process = picture or uploaded_file
if image_to_process:
# Display the image
st.image(image_to_process, caption='Uploaded/Captured Image', use_column_width=True)
# Extract text button
if st.button('Extract Text'):
# Show loading spinner
with st.spinner('Extracting text...'):
# Call the text extraction function
extracted_text = extract_text_from_image(image_to_process)
# Display the extracted text
st.subheader('Extracted Text:')
st.text_area("", value=extracted_text, height=300)
if __name__ == '__main__':
main()