Spaces:
Running
on
Zero
Running
on
Zero
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
# Default configuration template
|
4 |
+
default_config = {
|
5 |
+
'background': '/AutoGameBackgrounds/1stGameLoc123.png',
|
6 |
+
'inventory': [],
|
7 |
+
'skills': [],
|
8 |
+
'objectives': [],
|
9 |
+
'targets': [],
|
10 |
+
'story': [],
|
11 |
+
'actions': {}
|
12 |
+
}
|
13 |
+
|
14 |
+
# Helper functions to dynamically add items
|
15 |
+
def add_inventory_item(inventory_items, type, name, description):
|
16 |
+
new_item = {"type": type, "name": name, "description": description}
|
17 |
+
inventory_items.append(new_item)
|
18 |
+
return inventory_items
|
19 |
+
|
20 |
+
def add_skill(skills_items, branch, name, learned):
|
21 |
+
new_skill = {"branch": branch, "name": name, "learned": learned == 'True'}
|
22 |
+
skills_items.append(new_skill)
|
23 |
+
return skills_items
|
24 |
+
|
25 |
+
def add_objective(objectives_items, id, name, complete):
|
26 |
+
new_objective = {"id": id, "name": name, "complete": complete == 'True'}
|
27 |
+
objectives_items.append(new_objective)
|
28 |
+
return objectives_items
|
29 |
+
|
30 |
+
def add_target(targets_items, name, x, y, collisionType, collisiontext):
|
31 |
+
new_target = {"name": name, "x": int(x), "y": int(y), "collisionType": collisionType, "collisiontext": collisiontext}
|
32 |
+
targets_items.append(new_target)
|
33 |
+
return targets_items
|
34 |
+
|
35 |
+
with gr.Blocks() as demo:
|
36 |
+
inventory_items = gr.State([])
|
37 |
+
skills_items = gr.State([])
|
38 |
+
objectives_items = gr.State([])
|
39 |
+
targets_items = gr.State([])
|
40 |
+
|
41 |
+
with gr.Tabs():
|
42 |
+
with gr.TabItem("Inventory"):
|
43 |
+
inventory_type = gr.Textbox(label="Type")
|
44 |
+
inventory_name = gr.Textbox(label="Name")
|
45 |
+
inventory_description = gr.Textbox(label="Description")
|
46 |
+
add_inventory = gr.Button("Add Inventory Item")
|
47 |
+
inventory_textbox = gr.JSON(label="Inventory Items", value=[])
|
48 |
+
|
49 |
+
with gr.TabItem("Skills"):
|
50 |
+
skills_branch = gr.Textbox(label="Branch")
|
51 |
+
skills_name = gr.Textbox(label="Name")
|
52 |
+
skills_learned = gr.Dropdown(choices=["True", "False"], label="Learned")
|
53 |
+
add_skill_button = gr.Button("Add Skill")
|
54 |
+
skills_textbox = gr.JSON(label="Skills", value=[])
|
55 |
+
|
56 |
+
with gr.TabItem("Objectives"):
|
57 |
+
objectives_id = gr.Textbox(label="ID")
|
58 |
+
objectives_name = gr.Textbox(label="Name")
|
59 |
+
objectives_complete = gr.Dropdown(choices=["True", "False"], label="Complete")
|
60 |
+
add_objective_button = gr.Button("Add Objective")
|
61 |
+
objectives_textbox = gr.JSON(label="Objectives", value=[])
|
62 |
+
|
63 |
+
with gr.TabItem("Targets"):
|
64 |
+
targets_name = gr.Textbox(label="Name")
|
65 |
+
targets_x = gr.Textbox(label="X Coordinate")
|
66 |
+
targets_y = gr.Textbox(label="Y Coordinate")
|
67 |
+
targets_collisionType = gr.Textbox(label="Collision Type")
|
68 |
+
targets_collisiontext = gr.Textbox(label="Collision Text")
|
69 |
+
add_target_button = gr.Button("Add Target")
|
70 |
+
targets_textbox = gr.JSON(label="Targets", value=[])
|
71 |
+
|
72 |
+
config_output = gr.JSON(label="Updated Configuration")
|
73 |
+
|
74 |
+
@gr.render(inputs=[inventory_items, skills_items, objectives_items, targets_items]) #, outputs=config_output)
|
75 |
+
def aggregate_config(inventory, skills, objectives, targets):
|
76 |
+
config = default_config.copy()
|
77 |
+
config['inventory'] = inventory
|
78 |
+
config['skills'] = skills
|
79 |
+
config['objectives'] = objectives
|
80 |
+
config['targets'] = targets
|
81 |
+
return config
|
82 |
+
|
83 |
+
add_inventory.click(add_inventory_item, inputs=[inventory_items, inventory_type, inventory_name, inventory_description], outputs=inventory_textbox)
|
84 |
+
add_inventory.click(aggregate_config, inputs=[inventory_items, skills_items, objectives_items, targets_items], outputs=config_output)
|
85 |
+
|
86 |
+
add_skill_button.click(add_skill, inputs=[skills_items, skills_branch, skills_name, skills_learned], outputs=skills_textbox)
|
87 |
+
add_skill_button.click(aggregate_config, inputs=[inventory_items, skills_items, objectives_items, targets_items], outputs=config_output)
|
88 |
+
|
89 |
+
add_objective_button.click(add_objective, inputs=[objectives_items, objectives_id, objectives_name, objectives_complete], outputs=objectives_textbox)
|
90 |
+
add_objective_button.click(aggregate_config, inputs=[inventory_items, skills_items, objectives_items, targets_items], outputs=config_output)
|
91 |
+
|
92 |
+
add_target_button.click(add_target, inputs=[targets_items, targets_name, targets_x, targets_y, targets_collisionType, targets_collisiontext], outputs=targets_textbox)
|
93 |
+
add_target_button.click(aggregate_config, inputs=[inventory_items, skills_items, objectives_items, targets_items], outputs=config_output)
|
94 |
+
|
95 |
+
demo.launch()
|