mkoot007 commited on
Commit
9ca967b
·
1 Parent(s): bee1bfc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -23
app.py CHANGED
@@ -1,31 +1,30 @@
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)
 
 
 
 
1
  import streamlit as st
 
2
  from transformers import pipeline, set_seed
3
 
4
+ # Create a text generation pipeline with the "gpt2" model
5
+ text_generator = pipeline("text-generation", model="gpt2")
6
 
7
+ st.title("Story Generator")
 
8
 
9
+ # User inputs
10
+ title = st.text_input("Title of the Story:")
11
+ character = st.text_input("Character (Hero) Name:")
12
+ era = st.selectbox("Era of the Story:", ["Medieval", "Modern", "Future"])
 
 
13
  genre = st.selectbox("Genre:", ["Action", "Novelistic", "Love"])
14
  ending = st.selectbox("Ending:", ["Happy", "Sad"])
15
 
16
+ if st.button("Generate Story"):
17
+ if title and character:
18
+ # Prepare the prompt based on user inputs
19
+ prompt = f"In the {era} era, there was a character named {character}. This is the {genre} story of {character}, a {genre} story with a {ending} ending."
20
+
21
+ # Generate the story
22
+ set_seed(42) # Set a seed for reproducibility
23
+ story = text_generator(prompt, max_length=300, do_sample=True)[0]["generated_text"]
24
+
25
+ # Set the title
26
+ full_story = f"# {title}\n\n{story}"
27
+
28
+ st.markdown(full_story)
29
+ else:
30
+ st.warning("Please provide a title and character name.")