mkoot007 commited on
Commit
406f121
1 Parent(s): 34332b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -11
app.py CHANGED
@@ -1,5 +1,5 @@
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")
@@ -14,16 +14,13 @@ ending = st.selectbox("Ending:", ["Happy", "Sad"])
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
- story = f"# {title}\n\nOnce upon a time, in the {era} era, there was a character named {character}. "
24
- story += f"This is a {genre} story of {character}, a tale filled with {setting}, a story of {conflict}. "
25
- story += f"In the end, a {resolution}."
26
-
27
  st.markdown(story)
28
  else:
29
  st.warning("Please provide a title and character name.")
 
1
  import streamlit as st
2
+ from transformers import pipeline, set_seed
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")
 
14
 
15
  if st.button("Generate Story"):
16
  if title and character:
17
+ # Prepare a structured prompt for the story
18
+ prompt = f"Write a {genre} story titled '{title}' set in the {era} era. The main character, {character}, faces a {genre} adventure. In the end, the story has a {ending} ending."
19
+
20
+ # Generate the story
21
+ set_seed(42) # Set a seed for reproducibility
22
+ story = text_generator(prompt, max_length=300, do_sample=True)[0]["generated_text"]
23
+
 
 
 
24
  st.markdown(story)
25
  else:
26
  st.warning("Please provide a title and character name.")