Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,56 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
CLASSES = {
|
| 4 |
-
"learn"
|
| 5 |
-
"lead"
|
| 6 |
-
"heal"
|
| 7 |
}
|
| 8 |
|
| 9 |
QUESTS = {
|
| 10 |
-
"fear": "Conquer the Shadow
|
| 11 |
-
"time": "Recover the
|
| 12 |
-
"money": "
|
| 13 |
-
"confidence": "Drink from the
|
| 14 |
-
"focus": "
|
| 15 |
-
"motivation": "
|
| 16 |
-
"
|
| 17 |
}
|
| 18 |
|
| 19 |
def generate_hero(name, goal, challenge):
|
| 20 |
name = name.strip() or "Stranger"
|
| 21 |
goal = goal.lower()
|
| 22 |
challenge = challenge.lower()
|
|
|
|
| 23 |
hero_class = next((v for k, v in CLASSES.items() if k in goal), "Adventurer")
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
intro = (
|
| 27 |
-
f'In the age when legends were still being written
|
| 28 |
-
f'rose from
|
| 29 |
-
f'
|
| 30 |
-
f'
|
| 31 |
-
f'
|
| 32 |
)
|
| 33 |
|
| 34 |
-
return hero_class, quest
|
| 35 |
|
| 36 |
-
with gr.Blocks(title
|
| 37 |
-
gr.
|
| 38 |
|
| 39 |
with gr.Row():
|
| 40 |
-
name
|
| 41 |
-
goal
|
| 42 |
-
challenge = gr.Textbox(label
|
|
|
|
| 43 |
btn = gr.Button("Generate Hero", variant="primary")
|
| 44 |
-
hero_class = gr.Textbox(label= "Hero Class")
|
| 45 |
-
quest = gr.TextBox(label = "Main Quest")
|
| 46 |
-
story = gr.TextBox(label = "Stroy Introduction", lines = 10)
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
CLASSES = {
|
| 4 |
+
"learn": "Sage", "grow": "Druid", "build": "Artificer",
|
| 5 |
+
"lead": "Paladin", "create": "Bard", "fight": "Warrior",
|
| 6 |
+
"heal": "Cleric", "explore": "Ranger",
|
| 7 |
}
|
| 8 |
|
| 9 |
QUESTS = {
|
| 10 |
+
"fear": "Conquer the Shadow Keep of Inner Doubt",
|
| 11 |
+
"time": "Recover the Lost Hourglass of Priorities",
|
| 12 |
+
"money": "Reclaim the Treasury of the Forgotten Kingdom",
|
| 13 |
+
"confidence": "Drink from the Wellspring of Unshakeable Resolve",
|
| 14 |
+
"focus": "Destroy the Fog Wraith scattered across the realm",
|
| 15 |
+
"motivation": "Relight the Ancient Flame of Purpose",
|
| 16 |
+
"skill": "Apprentice under the Grandmaster hidden in the mountains",
|
| 17 |
}
|
| 18 |
|
| 19 |
def generate_hero(name, goal, challenge):
|
| 20 |
name = name.strip() or "Stranger"
|
| 21 |
goal = goal.lower()
|
| 22 |
challenge = challenge.lower()
|
| 23 |
+
|
| 24 |
hero_class = next((v for k, v in CLASSES.items() if k in goal), "Adventurer")
|
| 25 |
+
|
| 26 |
+
quest = next((v for k, v in QUESTS.items() if k in challenge),
|
| 27 |
+
"Unravel the Mystery at the Edge of the Known World")
|
| 28 |
+
|
| 29 |
intro = (
|
| 30 |
+
f'In the age when legends were still being written, {name} the {hero_class} '
|
| 31 |
+
f'rose from humble origins with one burning desire: to {goal.rstrip(".")}. '
|
| 32 |
+
f'Yet the path was not easy. {name} faced a great darkness — {challenge.rstrip(".")}. '
|
| 33 |
+
f'Undeterred, they set forth on the quest: to {quest.lower()}. '
|
| 34 |
+
f'The world would never be the same.'
|
| 35 |
)
|
| 36 |
|
| 37 |
+
return hero_class, quest, intro
|
| 38 |
|
| 39 |
+
with gr.Blocks(title="Hero Generator") as app:
|
| 40 |
+
gr.Markdown("# ⚔️ Hero Generator")
|
| 41 |
|
| 42 |
with gr.Row():
|
| 43 |
+
name = gr.Textbox(label="Name", placeholder="Your name")
|
| 44 |
+
goal = gr.Textbox(label="Goal", placeholder="e.g. learn to code")
|
| 45 |
+
challenge = gr.Textbox(label="Biggest Challenge", placeholder="e.g. lack of focus")
|
| 46 |
+
|
| 47 |
btn = gr.Button("Generate Hero", variant="primary")
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
hero_class = gr.Textbox(label="Hero Class")
|
| 50 |
+
quest = gr.Textbox(label="Main Quest")
|
| 51 |
+
story = gr.Textbox(label="Story Introduction", lines=5)
|
| 52 |
+
|
| 53 |
+
btn.click(generate_hero, inputs=[name, goal, challenge],
|
| 54 |
+
outputs=[hero_class, quest, story])
|
| 55 |
|
| 56 |
app.launch()
|