Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,35 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
# Load the model
|
5 |
story_generator = pipeline('text-generation', model='gpt2')
|
6 |
|
7 |
st.title('Interactive Story Creator')
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Text area for user input
|
10 |
user_input = st.text_area("Start your story here...", "Once upon a time")
|
11 |
|
12 |
if st.button('Generate Story Continuation'):
|
13 |
with st.spinner('AI is writing the story...'):
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
+
import requests
|
4 |
|
5 |
# Load the model
|
6 |
story_generator = pipeline('text-generation', model='gpt2')
|
7 |
|
8 |
st.title('Interactive Story Creator')
|
9 |
|
10 |
+
# Genre selection
|
11 |
+
genre = st.selectbox(
|
12 |
+
"Choose the genre of your story:",
|
13 |
+
('Fantasy', 'Sci-Fi', 'Mystery', 'Horror', 'Adventure', 'Romance')
|
14 |
+
)
|
15 |
+
|
16 |
# Text area for user input
|
17 |
user_input = st.text_area("Start your story here...", "Once upon a time")
|
18 |
|
19 |
if st.button('Generate Story Continuation'):
|
20 |
with st.spinner('AI is writing the story...'):
|
21 |
+
prompt = f"A {genre.lower()} story. {user_input}"
|
22 |
+
generated_story = story_generator(prompt, max_length=500)
|
23 |
+
story_text = generated_story[0]['generated_text']
|
24 |
+
st.text_area("Here's the continuation of your story:", story_text, height=250)
|
25 |
+
|
26 |
+
# Fetch an image related to the genre
|
27 |
+
response = requests.get(f"https://api.pexels.com/v1/search?query={genre.lower()}&per_page=1",
|
28 |
+
headers={"Authorization": "YOUR_API_KEY"})
|
29 |
+
if response.status_code == 200:
|
30 |
+
image_url = response.json()['photos'][0]['src']['original']
|
31 |
+
st.image(image_url, caption=f"Visualizing the {genre} genre")
|
32 |
+
else:
|
33 |
+
st.error("Failed to fetch image")
|
34 |
+
|
35 |
+
# Note: Replace 'YOUR_API_KEY' with your actual API key from Pexels or Unsplash.
|