Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Create a
|
| 5 |
-
text_generator = pipeline("
|
| 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 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
full_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.")
|