Spaces:
Runtime error
Runtime error
Logan Zoellner
commited on
Commit
·
0c696ac
1
Parent(s):
4ee9eee
randomize character creation
Browse files
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
import re
|
|
|
|
| 5 |
|
| 6 |
# GPT-J-6B API
|
| 7 |
API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-j-6B"
|
|
@@ -17,6 +19,64 @@ Bremen is a human wizard, he wears a blue robe and carries a wand.
|
|
| 17 |
examples = [["river"], ["night"], ["trees"],["table"],["laughs"]]
|
| 18 |
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def npc_generate(name,race,characterClass):
|
| 21 |
|
| 22 |
desc="{name} is a {race} {characterClass}".format(name=name,race=race,characterClass=characterClass)
|
|
@@ -85,9 +145,11 @@ with demo:
|
|
| 85 |
poem_txt = gr.Textbox(lines=7)
|
| 86 |
output_image = gr.Image(type="filepath", shape=(256,256))
|
| 87 |
|
|
|
|
| 88 |
b1 = gr.Button("Generate NPC")
|
| 89 |
b2 = gr.Button("Generate Image")
|
| 90 |
|
|
|
|
| 91 |
b1.click(npc_generate, inputs=[ input_name,input_race,input_class], outputs=poem_txt)
|
| 92 |
b2.click(poem_to_image, poem_txt, output_image)
|
| 93 |
#examples=examples
|
|
|
|
| 1 |
+
from asyncio import constants
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import os
|
| 5 |
import re
|
| 6 |
+
import random
|
| 7 |
|
| 8 |
# GPT-J-6B API
|
| 9 |
API_URL = "https://api-inference.huggingface.co/models/EleutherAI/gpt-j-6B"
|
|
|
|
| 19 |
examples = [["river"], ["night"], ["trees"],["table"],["laughs"]]
|
| 20 |
|
| 21 |
|
| 22 |
+
def npc_randomize():
|
| 23 |
+
#name is a random combination of syllables
|
| 24 |
+
vowels = "aeiou".split()
|
| 25 |
+
constants = "bcdfghjklmnpqrstvwxyz".split()
|
| 26 |
+
seperators="-'".split()
|
| 27 |
+
name =""
|
| 28 |
+
for i in range(random.randint(2,4)):
|
| 29 |
+
name += random.choice(constants)
|
| 30 |
+
name += random.choice(vowels)
|
| 31 |
+
if random.random()<0.5:
|
| 32 |
+
name += random.choice(constants)
|
| 33 |
+
if random.random()<0.1:
|
| 34 |
+
name += random.choice(seperators)
|
| 35 |
+
|
| 36 |
+
races="""
|
| 37 |
+
Dwarf
|
| 38 |
+
Elf
|
| 39 |
+
Halfling
|
| 40 |
+
Human
|
| 41 |
+
Dragonborn
|
| 42 |
+
Gnome
|
| 43 |
+
Half-elf
|
| 44 |
+
Half-orc
|
| 45 |
+
Tiefling
|
| 46 |
+
Aarakocra
|
| 47 |
+
Genasi
|
| 48 |
+
Goliath"""
|
| 49 |
+
|
| 50 |
+
races=[x.strip() for x in races]
|
| 51 |
+
|
| 52 |
+
race=random.choice(races)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
classes="""Barbarian
|
| 56 |
+
Bard
|
| 57 |
+
Cleric
|
| 58 |
+
Druid
|
| 59 |
+
Fighter
|
| 60 |
+
Monk
|
| 61 |
+
Paladin
|
| 62 |
+
Ranger
|
| 63 |
+
Rogue
|
| 64 |
+
Sorcerer
|
| 65 |
+
Warlock
|
| 66 |
+
Wizard""".split("\n")
|
| 67 |
+
|
| 68 |
+
classes=[x.strip() for x in classes]
|
| 69 |
+
|
| 70 |
+
characterClass=random.choice(classes)
|
| 71 |
+
|
| 72 |
+
return name,race,characterClass
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
|
| 80 |
def npc_generate(name,race,characterClass):
|
| 81 |
|
| 82 |
desc="{name} is a {race} {characterClass}".format(name=name,race=race,characterClass=characterClass)
|
|
|
|
| 145 |
poem_txt = gr.Textbox(lines=7)
|
| 146 |
output_image = gr.Image(type="filepath", shape=(256,256))
|
| 147 |
|
| 148 |
+
b0 = gr.Button("Randomize name,race and class")
|
| 149 |
b1 = gr.Button("Generate NPC")
|
| 150 |
b2 = gr.Button("Generate Image")
|
| 151 |
|
| 152 |
+
b0.click(npc_randomize,outputs=[input_name,input_race,input_class])
|
| 153 |
b1.click(npc_generate, inputs=[ input_name,input_race,input_class], outputs=poem_txt)
|
| 154 |
b2.click(poem_to_image, poem_txt, output_image)
|
| 155 |
#examples=examples
|