Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline, set_seed
|
|
|
|
|
3 |
text_generator = pipeline("text-generation", model="google/flan-t5-base")
|
4 |
|
5 |
st.title("Story Generator")
|
6 |
|
7 |
-
|
8 |
title = st.text_input("Title of the Story:")
|
9 |
character = st.text_input("Character (Hero) Name:")
|
10 |
era = st.selectbox("Era of the Story:", ["Medieval", "Modern", "Future"])
|
@@ -13,9 +15,14 @@ ending = st.selectbox("Ending:", ["Happy", "Sad"])
|
|
13 |
|
14 |
if st.button("Generate Story"):
|
15 |
if title and character:
|
|
|
16 |
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."
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
full_story = f"# {title}\n\n{story}"
|
20 |
|
21 |
st.markdown(full_story)
|
|
|
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 |
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)
|