import random import gradio as gr # ----------------------------------------- # OFFLINE STORY GENERATOR FUNCTION # ----------------------------------------- def generate_story(character, setting, mood): story_openings = [ f"{character} woke up one morning feeling incredibly {mood}.", f"In the heart of {setting}, {character} began an unusual day.", f"{character} always believed in dreams, but today felt different.", ] conflicts = [ f"Suddenly, a strange sound echoed through the {setting}.", f"Out of nowhere, a mysterious figure appeared before {character}.", f"The wind whispered secrets that only {character} could hear.", ] actions = [ f"With courage, {character} decided to follow the clues.", f"{character} took a deep breath and walked towards the unknown.", f"A spark of curiosity led {character} deeper into the {setting}.", ] resolutions = [ f"And in the end, {character} discovered something magical.", f"Surprisingly, the journey turned out to be the best adventure ever.", f"{character} returned home with a heart full of stories and wisdom.", ] story = [ random.choice(story_openings), random.choice(conflicts), random.choice(actions), random.choice(resolutions) ] return "\n".join(story) # ----------------------------------------- # GRADIO UI # ----------------------------------------- def story_interface(character, setting, mood): return generate_story(character, setting, mood) with gr.Blocks() as demo: gr.Markdown("## 📖 Offline Story Generator (No API, No Internet Required)") with gr.Row(): character = gr.Textbox(label="Character Name") setting = gr.Textbox(label="Setting (forest, city, school, etc.)") mood = gr.Textbox(label="Mood (happy, mysterious, adventurous, etc.)") generate_btn = gr.Button("Generate Story") output_story = gr.Textbox(label="Your Story", lines=8) generate_btn.click(story_interface, inputs=[character, setting, mood], outputs=output_story) # Start the app demo.launch()