Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
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.")
|