Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,31 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import io
|
| 3 |
-
from PIL import Image
|
| 4 |
-
import easyocr
|
| 5 |
from transformers import pipeline, set_seed
|
| 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 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
else:
|
| 35 |
-
st.warning("No text extracted from the image.")
|
| 36 |
-
|
| 37 |
-
else:
|
| 38 |
-
st.markdown("Please upload an image to extract text and generate a story.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import io
|
|
|
|
|
|
|
| 3 |
from transformers import pipeline, set_seed
|
| 4 |
|
| 5 |
+
# Create a text2text-generation pipeline with the "google/flan-t5-base" model
|
| 6 |
+
pipe = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 7 |
|
| 8 |
# Initialize the EasyOCR reader for text extraction from images
|
| 9 |
+
# ocr_reader = easyocr.Reader(['en'])
|
| 10 |
+
|
| 11 |
+
# Remove the text extraction code
|
| 12 |
+
|
| 13 |
+
# Create input fields for the title, character, era, genre, and ending
|
| 14 |
+
title = st.text_input("Title:")
|
| 15 |
+
character = st.text_input("Character (hero):")
|
| 16 |
+
era = st.text_input("Era of story:")
|
| 17 |
+
genre = st.selectbox("Genre:", ["Action", "Novelistic", "Love"])
|
| 18 |
+
ending = st.selectbox("Ending:", ["Happy", "Sad"])
|
| 19 |
+
|
| 20 |
+
# Generate a story prompt based on the user input
|
| 21 |
+
story_prompt = f"Once upon a time, in the {era}, there lived a {character} named {character}. {character} was a {genre} hero/heroine, and one day, they went on a quest to..."
|
| 22 |
+
|
| 23 |
+
# Set a seed for reproducibility
|
| 24 |
+
set_seed(42)
|
| 25 |
+
|
| 26 |
+
# Generate the story
|
| 27 |
+
story = pipe(story_prompt, max_length=300, do_sample=True)[0]["generated_text"]
|
| 28 |
+
|
| 29 |
+
# Display the story to the user
|
| 30 |
+
st.markdown("**Story:**")
|
| 31 |
+
st.markdown(story)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|