mkoot007 commited on
Commit
6bbc4d7
1 Parent(s): 1663636

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -1,12 +1,11 @@
1
  import streamlit as st
2
- from transformers import pipeline, set_seed
3
 
4
- # Create a text generation pipeline with the "google/flan-t5-base" model
5
- text_generator = pipeline("text-generation", model="google/flan-t5-base")
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"])
@@ -15,16 +14,16 @@ 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=500, 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.")
 
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
+ text_generator = pipeline("text2text-generation", model="google/flan-t5-base")
6
 
7
  st.title("Story Generator")
8
 
 
9
  title = st.text_input("Title of the Story:")
10
  character = st.text_input("Character (Hero) Name:")
11
  era = st.selectbox("Era of the Story:", ["Medieval", "Modern", "Future"])
 
14
 
15
  if st.button("Generate Story"):
16
  if title and character:
17
+ # Generate story elements using the model
18
+ setting = text_generator(f"Create the setting for a story set in the {era} era.")
19
+ conflict = text_generator(f"Describe the main conflict faced by the character {character}.")
20
+ resolution = text_generator(f"Provide a resolution for the {ending} ending.")
21
+
22
+ # Combine the elements into a full story
23
+ full_story = f"# {title}\n\nOnce upon a time, in the {era} era, there was a character named {character}. "
24
+ full_story += f"This is a {genre} story of {character}, a tale filled with {setting}, a story of {conflict}. "
25
+ full_story += f"In the end, a {resolution}."
26
+
27
  st.markdown(full_story)
28
  else:
29
  st.warning("Please provide a title and character name.")