Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,13 +4,13 @@ from PIL import Image
|
|
4 |
import easyocr
|
5 |
from transformers import pipeline
|
6 |
|
7 |
-
# Create a text2text-generation pipeline with the "t5-
|
8 |
pipe = pipeline("text2text-generation", model="t5-base")
|
9 |
|
10 |
# Initialize the EasyOCR reader for text extraction from images
|
11 |
ocr_reader = easyocr.Reader(['en'])
|
12 |
|
13 |
-
st.title("Text
|
14 |
|
15 |
uploaded_file = st.file_uploader("Upload an image:")
|
16 |
|
@@ -25,12 +25,13 @@ if uploaded_file is not None:
|
|
25 |
st.markdown(extracted_text)
|
26 |
|
27 |
if extracted_text:
|
28 |
-
# Use the pipeline to generate a
|
29 |
-
|
30 |
-
|
31 |
-
st.markdown(
|
|
|
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
|
|
|
4 |
import easyocr
|
5 |
from transformers import pipeline
|
6 |
|
7 |
+
# Create a text2text-generation pipeline with the "t5-base" model
|
8 |
pipe = pipeline("text2text-generation", model="t5-base")
|
9 |
|
10 |
# Initialize the EasyOCR reader for text extraction from images
|
11 |
ocr_reader = easyocr.Reader(['en'])
|
12 |
|
13 |
+
st.title("Text-to-Story Generator")
|
14 |
|
15 |
uploaded_file = st.file_uploader("Upload an image:")
|
16 |
|
|
|
25 |
st.markdown(extracted_text)
|
26 |
|
27 |
if extracted_text:
|
28 |
+
# Use the pipeline to generate a story based on the extracted text
|
29 |
+
story_prompt = f"Create a story based on the following text: '{extracted_text}'"
|
30 |
+
story = pipe(story_prompt, max_length=300, do_sample=True)[0]["generated_text"]
|
31 |
+
st.markdown("**Story:**")
|
32 |
+
st.markdown(story)
|
33 |
else:
|
34 |
st.warning("No text extracted from the image.")
|
35 |
|
36 |
else:
|
37 |
+
st.markdown("Please upload an image to extract text and generate a story.")
|