Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,36 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Create a text2text-generation pipeline with the "google/flan-t5-base" model
|
5 |
pipe = pipeline("text2text-generation", model="google/flan-t5-base")
|
6 |
|
|
|
|
|
|
|
7 |
st.title("Text Explanation Model")
|
8 |
-
user_text = st.text_area("Enter text:")
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
st.markdown(explanation)
|
16 |
else:
|
17 |
-
st.warning("
|
18 |
|
19 |
-
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import io
|
3 |
+
from PIL import Image
|
4 |
+
import easyocr
|
5 |
from transformers import pipeline
|
6 |
|
7 |
# Create a text2text-generation pipeline with the "google/flan-t5-base" model
|
8 |
pipe = pipeline("text2text-generation", model="google/flan-t5-base")
|
9 |
|
10 |
+
# Initialize the EasyOCR reader for text extraction from images
|
11 |
+
ocr_reader = easyocr.Reader(['en'])
|
12 |
+
|
13 |
st.title("Text Explanation Model")
|
|
|
14 |
|
15 |
+
uploaded_file = st.file_uploader("Upload an image:")
|
16 |
+
|
17 |
+
if uploaded_file is not None:
|
18 |
+
# Read the uploaded image
|
19 |
+
image = Image.open(uploaded_file)
|
20 |
+
|
21 |
+
# Extract text from the image using OCR
|
22 |
+
ocr_results = ocr_reader.readtext(image)
|
23 |
+
extracted_text = " ".join([res[1] for res in ocr_results])
|
24 |
+
st.markdown("**Extracted text:**")
|
25 |
+
st.markdown(extracted_text)
|
26 |
+
|
27 |
+
if extracted_text:
|
28 |
+
# Use the pipeline to generate a concise explanation
|
29 |
+
explanation = pipe(extracted_text, max_length=30, do_sample=True)[0]["generated_text"]
|
30 |
+
st.markdown("**Explanation (5-6 lines):**")
|
31 |
st.markdown(explanation)
|
32 |
else:
|
33 |
+
st.warning("No text extracted from the image.")
|
34 |
|
35 |
+
else:
|
36 |
+
st.markdown("Please upload an image to extract text and generate an explanation.")
|