Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,81 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def generate_character_description(name, gender, trait, superpower):
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# Generate the description
|
| 14 |
-
results = generator(prompt, max_length=100, num_return_sequences=1)
|
| 15 |
-
description = results[1]['generated_text']
|
| 16 |
|
| 17 |
-
|
| 18 |
-
return description[len(prompt):].strip()
|
| 19 |
|
| 20 |
# Gradio interface
|
| 21 |
iface = gr.Interface(
|
| 22 |
fn=generate_character_description,
|
| 23 |
inputs=[
|
| 24 |
-
gr.
|
| 25 |
-
gr.Radio(label="Gender", choices=
|
| 26 |
-
gr.
|
| 27 |
-
gr.
|
| 28 |
],
|
| 29 |
outputs="text",
|
| 30 |
title="Character Description Generator",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
|
| 4 |
+
# # Predefined lists for character descriptions
|
| 5 |
+
# names = ["Aria", "Bren", "Cyra", "Derek", "Elara", "Finn", "Gwen", "Hank"]
|
| 6 |
+
# genders = ["male", "female"]
|
| 7 |
+
traits = ["brave", "clever", "kind", "mysterious", "strong", "wise"]
|
| 8 |
+
superpowers = ["flying", "invisibility", "super strength", "telepathy", "time travel", "shape-shifting"]
|
| 9 |
+
|
| 10 |
+
# Example scenarios for different traits and superpowers
|
| 11 |
+
scenarios = {
|
| 12 |
+
"brave": {
|
| 13 |
+
"flying": "Soaring through the skies, {name} defends the helpless and battles evil forces.",
|
| 14 |
+
"invisibility": "In the shadows, {name} uses their power to uncover hidden secrets and protect the innocent.",
|
| 15 |
+
"super strength": "With unmatched power, {name} stands as a shield against all dangers, fighting for justice.",
|
| 16 |
+
"telepathy": "Reading minds, {name} can sense danger before it happens and guide others to safety.",
|
| 17 |
+
"time travel": "Venturing through time, {name} seeks to correct historical wrongs and ensure a better future.",
|
| 18 |
+
"shape-shifting": "Assuming different forms, {name} infiltrates enemy ranks and gathers crucial information."
|
| 19 |
+
},
|
| 20 |
+
"clever": {
|
| 21 |
+
"flying": "Using their intelligence and agility, {name} solves complex problems while soaring through the skies.",
|
| 22 |
+
"invisibility": "By becoming invisible, {name} cleverly outsmarts opponents and completes covert missions.",
|
| 23 |
+
"super strength": "With a mind as sharp as their muscles, {name} uses their strength to devise innovative solutions.",
|
| 24 |
+
"telepathy": "Strategically reading minds, {name} manipulates situations to their advantage and outwits adversaries.",
|
| 25 |
+
"time travel": "Navigating through different eras, {name} cleverly adjusts their plans to meet changing circumstances.",
|
| 26 |
+
"shape-shifting": "Transforming into various forms, {name} adapts quickly to solve problems and overcome obstacles."
|
| 27 |
+
},
|
| 28 |
+
"kind": {
|
| 29 |
+
"flying": "{name} flies gracefully to help those in need, offering support and comfort from above.",
|
| 30 |
+
"invisibility": "{name} uses their invisibility to provide quiet assistance and aid those who are in trouble.",
|
| 31 |
+
"super strength": "{name} uses their strength to protect and uplift others, always ready to lend a hand.",
|
| 32 |
+
"telepathy": "{name} senses the emotions of others and offers empathy and guidance to those who need it.",
|
| 33 |
+
"time travel": "{name} travels through time to assist and support others, ensuring their well-being across eras.",
|
| 34 |
+
"shape-shifting": "{name} transforms into different forms to provide help and comfort to those around them."
|
| 35 |
+
},
|
| 36 |
+
"mysterious": {
|
| 37 |
+
"flying": "{name} glides through the clouds, their true motives and intentions remaining a mystery.",
|
| 38 |
+
"invisibility": "{name} remains hidden in the shadows, revealing their presence only when necessary.",
|
| 39 |
+
"super strength": "{name} displays their immense power with an enigmatic aura, leaving others in awe and uncertainty.",
|
| 40 |
+
"telepathy": "{name} communicates silently, their thoughts and intentions shrouded in secrecy.",
|
| 41 |
+
"time travel": "{name} moves through time with an air of enigma, their purpose and actions often unclear.",
|
| 42 |
+
"shape-shifting": "{name} shifts forms unpredictably, keeping others guessing about their true identity."
|
| 43 |
+
},
|
| 44 |
+
"strong": {
|
| 45 |
+
"flying": "{name} flies with unwavering strength, overcoming any obstacles in their path and protecting the skies.",
|
| 46 |
+
"invisibility": "{name} uses their power to strike decisively from the shadows, with immense force and precision.",
|
| 47 |
+
"super strength": "{name} showcases their physical prowess, crushing barriers and defeating foes with sheer might.",
|
| 48 |
+
"telepathy": "{name} uses their mental strength to control and influence others, bending minds to their will.",
|
| 49 |
+
"time travel": "{name} travels through time with the strength to face any challenge, reshaping history with power.",
|
| 50 |
+
"shape-shifting": "{name} transforms into powerful forms, using their enhanced abilities to dominate and control."
|
| 51 |
+
},
|
| 52 |
+
"wise": {
|
| 53 |
+
"flying": "{name} flies high, offering sage advice and guidance to those they encounter from above.",
|
| 54 |
+
"invisibility": "{name} remains unseen, providing wisdom and insights discreetly to those who seek it.",
|
| 55 |
+
"super strength": "{name} uses their strength wisely, knowing when to act and when to support others quietly.",
|
| 56 |
+
"telepathy": "{name} reads minds with profound understanding, offering guidance and solutions to complex problems.",
|
| 57 |
+
"time travel": "{name} travels through time with a deep knowledge of history, correcting mistakes with careful precision.",
|
| 58 |
+
"shape-shifting": "{name} adapts to various forms, using their wisdom to make the best decisions in any situation."
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
|
| 62 |
def generate_character_description(name, gender, trait, superpower):
|
| 63 |
+
# Ensure the trait and superpower exist in the scenarios dictionary
|
| 64 |
+
if trait in scenarios and superpower in scenarios[trait]:
|
| 65 |
+
description = scenarios[trait][superpower].format(name=name)
|
| 66 |
+
else:
|
| 67 |
+
description = f"{name} is a character with a {trait} personality and the superpower of {superpower}. More details to come!"
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
return description
|
|
|
|
| 70 |
|
| 71 |
# Gradio interface
|
| 72 |
iface = gr.Interface(
|
| 73 |
fn=generate_character_description,
|
| 74 |
inputs=[
|
| 75 |
+
gr.Dropdown(label="Name", choices=names, default=names[0]),
|
| 76 |
+
gr.Radio(label="Gender", choices=genders),
|
| 77 |
+
gr.Dropdown(label="Personality Trait", choices=traits, default=traits[0]),
|
| 78 |
+
gr.Dropdown(label="Superpower", choices=superpowers, default=superpowers[0])
|
| 79 |
],
|
| 80 |
outputs="text",
|
| 81 |
title="Character Description Generator",
|