Spaces:
Runtime error
Runtime error
import streamlit as st | |
from transformers import pipeline | |
# Initialize the Hugging Face pipeline for text generation | |
generator = pipeline("text-generation", model="gpt2") | |
# Streamlit app layout | |
st.title("AI Story Generator - Creativista ") | |
# Prompt input from the user | |
prompt = st.text_input("Enter a prompt:", "") | |
# Slider to control the length of the generated story | |
max_length = st.slider("Select the maximum length of the story (in words):", | |
min_value=50, max_value=500, value=100, step=10) | |
# Button to trigger the story generation | |
if st.button("Generate Story"): | |
if prompt: | |
# Generate the story based on the prompt | |
result = generator(prompt, max_length=max_length, num_return_sequences=1) | |
# Display the generated story | |
st.write(result[0]['generated_text']) | |
else: | |
st.write("Please enter a prompt to generate a story.") | |