mkoot007 commited on
Commit
bee1bfc
·
1 Parent(s): 82597df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -32
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
- st.title("Text-to-Story Generator")
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 story based on the extracted text
29
- story_prompt = f"Once upon a time, in a world where '{extracted_text}',"
30
- set_seed(42) # Set a seed for reproducibility
31
- story = pipe(story_prompt, max_length=300, do_sample=True)[0]["generated_text"]
32
- st.markdown("**Story:**")
33
- st.markdown(story)
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)