Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import random | |
| # --- Helper functions --- | |
| def generate_characters(genre): | |
| """Generate character names based on genre.""" | |
| names = { | |
| "Fantasy": ["Eldric", "Lyra", "Thalion", "Seraphina"], | |
| "Sci-Fi": ["Nova", "Orion", "Zephyr", "Astra"], | |
| "Romance": ["Emma", "Liam", "Sophia", "Noah"], | |
| "Mystery": ["Detective Grey", "Iris Black", "Victor Holt", "Clara Dane"], | |
| "Horror": ["Damien", "Lilith", "Victor", "Morgana"], | |
| "Adventure": ["Jack", "Lara", "Max", "Elena"] | |
| } | |
| return random.sample(names.get(genre, ["Alex", "Sam", "Jordan", "Taylor"]), 2) | |
| def generate_story_plot(genre, characters): | |
| """Generate a story plot based on genre and characters.""" | |
| plots = { | |
| "Fantasy": f"{characters[0]} and {characters[1]} must retrieve a magical artifact to save their kingdom from darkness.", | |
| "Sci-Fi": f"{characters[0]} and {characters[1]} travel across galaxies to prevent an interstellar war.", | |
| "Romance": f"{characters[0]} meets {characters[1]} in an unexpected place, and love blossoms amidst challenges.", | |
| "Mystery": f"{characters[0]} and {characters[1]} investigate a string of unexplained events in a small town.", | |
| "Horror": f"{characters[0]} and {characters[1]} find themselves trapped in a haunted mansion with dark secrets.", | |
| "Adventure": f"{characters[0]} and {characters[1]} embark on a perilous journey to find a lost treasure." | |
| } | |
| return plots.get(genre, f"{characters[0]} and {characters[1]} go on an exciting adventure.") | |
| def generate_dialogue(characters): | |
| """Generate a simple dialogue between two characters.""" | |
| dialogues = [ | |
| f"{characters[0]}: 'We have to keep going, no matter what.'\n{characters[1]}: 'I know. I trust you.'", | |
| f"{characters[0]}: 'Did you hear that?'\n{characters[1]}: 'Yes… something’s coming.'", | |
| f"{characters[0]}: 'This is our only chance.'\n{characters[1]}: 'Then let's make it count.'" | |
| ] | |
| return random.choice(dialogues) | |
| # --- Streamlit UI --- | |
| st.set_page_config(page_title="Story & Character Generator", page_icon="📖") | |
| st.title("📖 Story & Character Generator") | |
| st.write("Enter a genre, and get a story plot, character names, and dialogues!") | |
| genre = st.selectbox( | |
| "Choose a genre:", | |
| ["Fantasy", "Sci-Fi", "Romance", "Mystery", "Horror", "Adventure"] | |
| ) | |
| if st.button("Generate Story"): | |
| characters = generate_characters(genre) | |
| plot = generate_story_plot(genre, characters) | |
| dialogue = generate_dialogue(characters) | |
| st.subheader("✨ Characters") | |
| st.write(", ".join(characters)) | |
| st.subheader("📜 Story Plot") | |
| st.write(plot) | |
| st.subheader("💬 Dialogue Example") | |
| st.code(dialogue) | |