rockerritesh
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
def extract_text_from_image(uploaded_file):
|
5 |
+
"""Upload image to the text extraction API and return extracted text"""
|
6 |
+
files = {'image': uploaded_file}
|
7 |
+
|
8 |
+
try:
|
9 |
+
response = requests.post('https://api-1-zvvu.onrender.com/upload', files=files)
|
10 |
+
|
11 |
+
if response.status_code == 200:
|
12 |
+
return response.text
|
13 |
+
else:
|
14 |
+
return f"Error: {response.status_code} - {response.text}"
|
15 |
+
|
16 |
+
except requests.RequestException as e:
|
17 |
+
return f"Request failed: {e}"
|
18 |
+
|
19 |
+
def main():
|
20 |
+
st.title('Image Text Extraction')
|
21 |
+
|
22 |
+
# Camera input toggle
|
23 |
+
enable = st.checkbox("Enable camera")
|
24 |
+
|
25 |
+
# Camera input
|
26 |
+
picture = st.camera_input("Take a picture", disabled=not enable)
|
27 |
+
|
28 |
+
# File uploader
|
29 |
+
uploaded_file = st.file_uploader("Or upload an image...", type=['png', 'jpg', 'jpeg'])
|
30 |
+
|
31 |
+
# Determine which image to use
|
32 |
+
image_to_process = picture or uploaded_file
|
33 |
+
|
34 |
+
if image_to_process:
|
35 |
+
# Display the image
|
36 |
+
st.image(image_to_process, caption='Uploaded/Captured Image', use_column_width=True)
|
37 |
+
|
38 |
+
# Extract text button
|
39 |
+
if st.button('Extract Text'):
|
40 |
+
# Show loading spinner
|
41 |
+
with st.spinner('Extracting text...'):
|
42 |
+
# Call the text extraction function
|
43 |
+
extracted_text = extract_text_from_image(image_to_process)
|
44 |
+
|
45 |
+
# Display the extracted text
|
46 |
+
st.subheader('Extracted Text:')
|
47 |
+
st.text_area("", value=extracted_text, height=300)
|
48 |
+
|
49 |
+
if __name__ == '__main__':
|
50 |
+
main()
|