shaikafnan commited on
Commit
034f411
·
verified ·
1 Parent(s): b131842

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -59
app.py CHANGED
@@ -1,8 +1,10 @@
1
- > Virat:
2
  import random
 
3
 
 
 
 
4
  def generate_story(character, setting, mood):
5
-
6
  story_openings = [
7
  f"{character} woke up one morning feeling incredibly {mood}.",
8
  f"In the heart of {setting}, {character} began an unusual day.",
@@ -27,7 +29,6 @@ def generate_story(character, setting, mood):
27
  f"{character} returned home with a heart full of stories and wisdom.",
28
  ]
29
 
30
- # Pick random lines
31
  story = [
32
  random.choice(story_openings),
33
  random.choice(conflicts),
@@ -38,62 +39,25 @@ def generate_story(character, setting, mood):
38
  return "\n".join(story)
39
 
40
 
41
- # -----------------------------
42
- # RUN THE STORY GENERATOR
43
- # -----------------------------
44
- character = input("Enter a character name: ")
45
- setting = input("Enter a setting: ")
46
- mood = input("Enter a mood (happy, mysterious, adventurous, etc.): ")
47
-
48
- print("\n Your Story:\n")
49
- print(generate_story(character, setting, mood))
50
-
51
- > Virat:
52
- import random
53
 
54
- def generate_story(character, setting, mood):
 
55
 
56
- story_openings = [
57
- f"{character} woke up one morning feeling incredibly {mood}.",
58
- f"In the heart of {setting}, {character} began an unusual day.",
59
- f"{character} always believed in dreams, but today felt different.",
60
- ]
61
-
62
- conflicts = [
63
- f"Suddenly, a strange sound echoed through the {setting}.",
64
- f"Out of nowhere, a mysterious figure appeared before {character}.",
65
- f"The wind whispered secrets that only {character} could hear.",
66
- ]
67
-
68
- actions = [
69
- f"With courage, {character} decided to follow the clues.",
70
- f"{character} took a deep breath and walked towards the unknown.",
71
- f"A spark of curiosity led {character} deeper into the {setting}.",
72
- ]
73
-
74
- resolutions = [
75
- f"And in the end, {character} discovered something magical.",
76
- f"Surprisingly, the journey turned out to be the best adventure ever.",
77
- f"{character} returned home with a heart full of stories and wisdom.",
78
- ]
79
-
80
- # Pick random lines
81
- story = [
82
- random.choice(story_openings),
83
- random.choice(conflicts),
84
- random.choice(actions),
85
- random.choice(resolutions)
86
- ]
87
-
88
- return "\n".join(story)
89
-
90
-
91
- # -----------------------------
92
- # RUN THE STORY GENERATOR
93
- # -----------------------------
94
- character = input("Enter a character name: ")
95
- setting = input("Enter a setting: ")
96
- mood = input("Enter a mood (happy, mysterious, adventurous, etc.): ")
97
 
98
- print("\n Your Story:\n")
99
- print(generate_story(character, setting, mood))
 
 
1
  import random
2
+ import gradio as gr
3
 
4
+ # -----------------------------------------
5
+ # OFFLINE STORY GENERATOR FUNCTION
6
+ # -----------------------------------------
7
  def generate_story(character, setting, mood):
 
8
  story_openings = [
9
  f"{character} woke up one morning feeling incredibly {mood}.",
10
  f"In the heart of {setting}, {character} began an unusual day.",
 
29
  f"{character} returned home with a heart full of stories and wisdom.",
30
  ]
31
 
 
32
  story = [
33
  random.choice(story_openings),
34
  random.choice(conflicts),
 
39
  return "\n".join(story)
40
 
41
 
42
+ # -----------------------------------------
43
+ # GRADIO UI
44
+ # -----------------------------------------
45
+ def story_interface(character, setting, mood):
46
+ return generate_story(character, setting, mood)
 
 
 
 
 
 
 
47
 
48
+ with gr.Blocks() as demo:
49
+ gr.Markdown("## 📖 Offline Story Generator (No API, No Internet Required)")
50
 
51
+ with gr.Row():
52
+ character = gr.Textbox(label="Character Name")
53
+ setting = gr.Textbox(label="Setting (forest, city, school, etc.)")
54
+ mood = gr.Textbox(label="Mood (happy, mysterious, adventurous, etc.)")
55
+
56
+ generate_btn = gr.Button("Generate Story")
57
+
58
+ output_story = gr.Textbox(label="Your Story", lines=8)
59
+
60
+ generate_btn.click(story_interface, inputs=[character, setting, mood], outputs=output_story)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
+ # Start the app
63
+ demo.launch()