panchadip commited on
Commit
6441210
·
verified ·
1 Parent(s): 3600322

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -20
app.py CHANGED
@@ -1,30 +1,25 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
- import torch
4
 
5
- # Initialize the text generation pipeline with a CPU device
6
- generator = pipeline("text-generation", model="gpt2", device=torch.device('cpu'))
7
 
8
  # Streamlit app layout
9
- st.title("AI Story Generator")
10
- st.write("Generate stories based on your custom prompt!")
11
 
12
- # Input prompt for the user
13
- prompt = st.text_input("Enter a story prompt:")
14
 
15
- # Generate button to start the story generation
 
 
 
 
16
  if st.button("Generate Story"):
17
  if prompt:
18
- try:
19
- # Generate story based on the prompt
20
- result = generator(prompt, max_length=100, num_return_sequences=1)
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.warning("Please enter a prompt to generate a story.")
 
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.")