|
import streamlit as st |
|
from transformers import pipeline |
|
import requests |
|
|
|
|
|
story_generator = pipeline('text-generation', model='gpt2') |
|
|
|
st.title('Interactive Short-Story Creator') |
|
|
|
|
|
genre = st.selectbox( |
|
"Choose the genre of your story:", |
|
('Fantasy', 'Sci-Fi', 'Mystery', 'Horror', 'Adventure', 'Romance') |
|
) |
|
|
|
|
|
user_input = st.text_area("Start your story here...", "Once upon a time") |
|
|
|
if st.button('Generate Story Continuation'): |
|
with st.spinner('AI is writing the story...'): |
|
prompt = f"A {genre.lower()} story. {user_input}" |
|
generated_story = story_generator(prompt, max_length=500) |
|
story_text = generated_story[0]['generated_text'] |
|
st.text_area("Here's the continuation of your story:", story_text, height=250) |
|
|
|
|
|
response = requests.get(f"https://api.pexels.com/v1/search?query={genre.lower()}&per_page=1", |
|
headers={"Authorization": "YOUR_API_KEY"}) |
|
if response.status_code == 200: |
|
image_url = response.json()['photos'][0]['src']['original'] |
|
st.image(image_url, caption=f"Visualizing the {genre} genre") |
|
else: |
|
st.error("Failed to fetch image") |
|
|
|
|
|
|