Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,25 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
-
import torch
|
4 |
|
5 |
-
# Initialize the
|
6 |
-
generator = pipeline("text-generation", model="gpt2"
|
7 |
|
8 |
# Streamlit app layout
|
9 |
-
st.title("AI Story Generator")
|
10 |
-
st.write("Generate stories based on your custom prompt!")
|
11 |
|
12 |
-
#
|
13 |
-
prompt = st.text_input("Enter a
|
14 |
|
15 |
-
#
|
|
|
|
|
|
|
|
|
16 |
if st.button("Generate Story"):
|
17 |
if prompt:
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
# Display the generated story
|
23 |
-
st.subheader("Generated Story:")
|
24 |
-
st.write(result[0]['generated_text'])
|
25 |
-
|
26 |
-
except Exception as e:
|
27 |
-
# Display any errors that occur during generation
|
28 |
-
st.error(f"An error occurred: {str(e)}")
|
29 |
else:
|
30 |
-
st.
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
+
# Initialize the Hugging Face pipeline for text generation
|
5 |
+
generator = pipeline("text-generation", model="gpt2")
|
6 |
|
7 |
# Streamlit app layout
|
8 |
+
st.title("AI Story Generator - Creativista ")
|
|
|
9 |
|
10 |
+
# Prompt input from the user
|
11 |
+
prompt = st.text_input("Enter a prompt:", "")
|
12 |
|
13 |
+
# Slider to control the length of the generated story
|
14 |
+
max_length = st.slider("Select the maximum length of the story (in words):",
|
15 |
+
min_value=50, max_value=500, value=100, step=10)
|
16 |
+
|
17 |
+
# Button to trigger the story generation
|
18 |
if st.button("Generate Story"):
|
19 |
if prompt:
|
20 |
+
# Generate the story based on the prompt
|
21 |
+
result = generator(prompt, max_length=max_length, num_return_sequences=1)
|
22 |
+
# Display the generated story
|
23 |
+
st.write(result[0]['generated_text'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
else:
|
25 |
+
st.write("Please enter a prompt to generate a story.")
|