Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,32 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
from
|
4 |
-
from
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
explainer = AutoModelForSequenceClassification.from_pretrained("bart-explainer")
|
9 |
|
10 |
-
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
tokenizer = AutoTokenizer.from_pretrained("bart-large")
|
16 |
-
encoded_text = tokenizer(text, return_tensors="pt")
|
17 |
-
explanation = explainer.generate(encoded_text)
|
18 |
-
return explanation[0]
|
19 |
|
20 |
-
#
|
21 |
-
st.
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
#
|
24 |
-
|
|
|
|
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
image = torch.from_numpy(uploaded_file.read()).unsqueeze(0)
|
29 |
-
extracted_text = extract_text(image)
|
30 |
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
# Display the extracted text and explanation
|
35 |
-
st.markdown("**Extracted text:**")
|
36 |
-
st.markdown(extracted_text)
|
37 |
-
|
38 |
-
st.markdown("**Explanation:**")
|
39 |
-
st.markdown(explanation)
|
40 |
-
|
41 |
-
else:
|
42 |
-
st.markdown("Please upload an image to extract text and get an explanation.")
|
|
|
1 |
import streamlit as st
|
2 |
+
import easyocr
|
3 |
+
from gtts import gTTS
|
4 |
+
from IPython.display import Audio
|
5 |
|
6 |
+
# Create Streamlit app title
|
7 |
+
st.title("Image Text-to-Speech App")
|
|
|
8 |
|
9 |
+
# Upload image
|
10 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
|
11 |
|
12 |
+
if uploaded_image is not None:
|
13 |
+
image = uploaded_image.read()
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
# Perform OCR on the uploaded image
|
16 |
+
st.header("Text Extracted from Image:")
|
17 |
+
reader = easyocr.Reader(['en'])
|
18 |
+
result = reader.readtext(image)
|
19 |
+
extracted_text = " ".join([res[1] for res in result])
|
20 |
+
st.write(extracted_text)
|
21 |
|
22 |
+
# Perform text-to-speech conversion
|
23 |
+
st.header("Text-to-Speech:")
|
24 |
+
tts = gTTS(extracted_text)
|
25 |
+
tts.save("output.mp3")
|
26 |
|
27 |
+
# Display the audio player
|
28 |
+
st.audio("output.mp3")
|
|
|
|
|
29 |
|
30 |
+
# Information for the user
|
31 |
+
st.info("Upload an image, and this app will extract the text and convert it to speech.")
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|