File size: 955 Bytes
bec6716
82597df
e26d0de
bec6716
9ca967b
e26d0de
b26992d
9ca967b
 
 
bee1bfc
 
 
9ca967b
 
 
b26992d
e26d0de
9ca967b
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import streamlit as st
from transformers import pipeline, set_seed
text_generator = pipeline("text-generation", model="google/flan-t5-base")

st.title("Story Generator")


title = st.text_input("Title of the Story:")
character = st.text_input("Character (Hero) Name:")
era = st.selectbox("Era of the Story:", ["Medieval", "Modern", "Future"])
genre = st.selectbox("Genre:", ["Action", "Novelistic", "Love"])
ending = st.selectbox("Ending:", ["Happy", "Sad"])

if st.button("Generate Story"):
    if title and character:
        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."
        set_seed(42)
        story = text_generator(prompt, max_length=300, do_sample=True)[0]["generated_text"]
        full_story = f"# {title}\n\n{story}"
        
        st.markdown(full_story)
    else:
        st.warning("Please provide a title and character name.")