rockerritesh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
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"""
|
@@ -9,13 +10,21 @@ def extract_text_from_image(uploaded_file):
|
|
9 |
response = requests.post('https://api-1-zvvu.onrender.com/upload', files=files)
|
10 |
|
11 |
if response.status_code == 200:
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
+
import json # Add this import to parse JSON responses
|
4 |
|
5 |
def extract_text_from_image(uploaded_file):
|
6 |
"""Upload image to the text extraction API and return extracted text"""
|
|
|
10 |
response = requests.post('https://api-1-zvvu.onrender.com/upload', files=files)
|
11 |
|
12 |
if response.status_code == 200:
|
13 |
+
# Parse JSON response
|
14 |
+
response_data = response.json()
|
15 |
+
if "text" in response_data:
|
16 |
+
# Load text as a Python object if it's JSON stringified
|
17 |
+
extracted_text = json.loads(response_data["text"])
|
18 |
+
return "\n".join(extracted_text) if isinstance(extracted_text, list) else extracted_text
|
19 |
+
else:
|
20 |
+
return "No text found in the response."
|
21 |
else:
|
22 |
return f"Error: {response.status_code} - {response.text}"
|
23 |
|
24 |
except requests.RequestException as e:
|
25 |
return f"Request failed: {e}"
|
26 |
|
27 |
+
|
28 |
def main():
|
29 |
st.title('Image Text Extraction')
|
30 |
|