Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,30 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import io
|
| 3 |
from transformers import pipeline, set_seed
|
| 4 |
|
| 5 |
-
# Create a
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
# ocr_reader = easyocr.Reader(['en'])
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
character = st.text_input("Character (hero):")
|
| 16 |
-
era = st.text_input("Era of story:")
|
| 17 |
genre = st.selectbox("Genre:", ["Action", "Novelistic", "Love"])
|
| 18 |
ending = st.selectbox("Ending:", ["Happy", "Sad"])
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
#
|
| 27 |
-
story =
|
| 28 |
-
|
| 29 |
-
#
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
from transformers import pipeline, set_seed
|
| 3 |
|
| 4 |
+
# Create a text generation pipeline with the "gpt2" model
|
| 5 |
+
text_generator = pipeline("text-generation", model="gpt2")
|
| 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"])
|
|
|
|
|
|
|
| 13 |
genre = st.selectbox("Genre:", ["Action", "Novelistic", "Love"])
|
| 14 |
ending = st.selectbox("Ending:", ["Happy", "Sad"])
|
| 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=300, 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)
|
| 29 |
+
else:
|
| 30 |
+
st.warning("Please provide a title and character name.")
|