Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,29 @@
|
|
| 1 |
-
import
|
| 2 |
-
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
|
|
|
| 5 |
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline, set_seed
|
| 3 |
|
| 4 |
+
# Load the text generation pipeline
|
| 5 |
+
text_generator = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 6 |
|
| 7 |
+
# Streamlit interface for story generation
|
| 8 |
+
st.title("Story Generator")
|
| 9 |
|
| 10 |
+
# Input fields for story parameters
|
| 11 |
+
title = st.text_input("Title of the Story:")
|
| 12 |
+
character = st.text_input("Character (Hero) Name:")
|
| 13 |
+
era = st.selectbox("Era of the Story:", ["Medieval", "Modern", "Future"])
|
| 14 |
+
genre = st.selectbox("Genre:", ["Action", "Novelistic", "Love"])
|
| 15 |
+
punchline = st.text_area("Punchline (Describe what the story is about):")
|
| 16 |
+
story_length = st.slider("Story Length", min_value=100, max_value=2000, step=100)
|
| 17 |
+
generate_button = st.button("Generate Story")
|
| 18 |
+
|
| 19 |
+
# Generate story based on user inputs
|
| 20 |
+
if generate_button:
|
| 21 |
+
if title and character and punchline:
|
| 22 |
+
prompt = f"Write a {genre} story titled '{title}' set in the {era} era. The main character, {character}, faces a {genre} adventure. The story is about '{punchline}'."
|
| 23 |
+
|
| 24 |
+
set_seed(42)
|
| 25 |
+
full_story = text_generator(prompt, max_length=story_length, do_sample=True)[0]["generated_text"]
|
| 26 |
+
|
| 27 |
+
st.markdown(full_story)
|
| 28 |
+
else:
|
| 29 |
+
st.warning("Please provide a title, character name, and punchline.")
|