File size: 2,175 Bytes
7d5152c
034f411
7d5152c
034f411
 
 
7d5152c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
034f411
 
 
 
 
7d5152c
034f411
 
7d5152c
034f411
 
 
 
 
 
 
 
 
 
7d5152c
034f411
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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()