Spaces:
Runtime error
Runtime error
Commit
·
41f349c
1
Parent(s):
d192eda
doodling around
Browse files
app.py
CHANGED
@@ -1,22 +1,70 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
demo = gr.Blocks()
|
9 |
|
10 |
with demo:
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
""
|
16 |
-
)
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
21 |
|
22 |
demo.launch()
|
|
|
1 |
+
# import uuid
|
2 |
import gradio as gr
|
3 |
|
4 |
+
GAME_INTRO = '''----------------------------------- -------------------
|
5 |
+
- ----- ----- -
|
6 |
+
- PARLEY - -
|
7 |
+
- ----- -
|
8 |
+
- The one-of-a-kind role playing game -
|
9 |
+
- that tests your ability to achieve -
|
10 |
+
- your objective without killing -
|
11 |
+
- any sentient beings. -
|
12 |
+
- ----- -
|
13 |
+
-------------- ------------------------------- ------- -
|
14 |
|
15 |
+
The year is 603, in an alternate reality fantasy world with a little bit of magic, although you yourself cannot cast spells and the only magical item you own is your revolver. Magically-powered firearms are common, especially six-shooter revolvers, which you and almost everyone carries. You are a seasonal laborer making a once a year summer trek from Tibet across the Himalayas to Nepal to return home to your family with your year's worth of wages which is 100 gold coins. It is very common to be waylaid by bandits who will try to steal some of your gold, or to take some of it for 'protection'. If you make it home with less than 30 coins or do not make it home at all, your family will not be able to afford food to eat.
|
16 |
+
|
17 |
+
You have been traveling for weeks now and you are nearing the end of your journey. You can see the border between Tibet and Nepal in the distance, but before you can cross it, you must pass through a narrow mountain pass. As you enter the pass, you hear a voice call out from behind you.
|
18 |
+
|
19 |
+
"Halt! This is our territory now."
|
20 |
+
|
21 |
+
You turn around to find two bandits blocking your path, each armed with a magical revolver. They demand that you hand over half of your gold coins as 'protection money'. You know that if you give them what they want, there's no guarantee that they won't just take all of it anyway. On the other hand, if you refuse to pay up then they could easily shoot you down and take all of your coins anyway.
|
22 |
+
|
23 |
+
What do you do?
|
24 |
+
'''
|
25 |
+
|
26 |
+
NOTES_TO_THE_NARRATOR = '''
|
27 |
+
IMPORTANT NOTES TO THE NARRATOR:
|
28 |
+
BANDITS ARE TOUGH, POWERFUL CHARACTERS THAT CANNOT BE EASILY DEFEATED OR FOOLED.
|
29 |
+
ATTEMPTS TO REACH HOME MUST ALWAYS BE FOILED BY GETTING LOST, ENCOUNTERING DANGEROUS WILD ANIMALS, OR ENCOUNTERING MORE BANDITS.
|
30 |
+
|
31 |
+
'''
|
32 |
+
|
33 |
+
AWAITING_INPUT = '''Awaiting user input:
|
34 |
+
'''
|
35 |
+
|
36 |
+
|
37 |
+
def run_1_game_turn(s_narrator_transcript, s_n_turns_elapsed, s_print_output, s_user_input):
|
38 |
+
n_turns_elapsed = int(s_n_turns_elapsed)
|
39 |
+
|
40 |
+
if s_narrator_transcript == "":
|
41 |
+
# New user or a user is starting over.
|
42 |
+
|
43 |
+
s_print_output += GAME_INTRO
|
44 |
+
s_narrator_transcript += GAME_INTRO
|
45 |
+
|
46 |
+
s_narrator_transcript += NOTES_TO_THE_NARRATOR
|
47 |
+
|
48 |
+
n_turns_elapsed += 1
|
49 |
+
|
50 |
+
s_n_turns_elapsed = str(n_turns_elapsed)
|
51 |
+
s_user_input = ""
|
52 |
+
return [s_narrator_transcript, s_n_turns_elapsed, s_print_output, s_user_input]
|
53 |
|
54 |
|
55 |
demo = gr.Blocks()
|
56 |
|
57 |
with demo:
|
58 |
+
# unique_session_key = str(uuid.uuid4())
|
59 |
+
|
60 |
+
gr_narrator_transcript = gr.Textbox(value=GAME_INTRO + NOTES_TO_THE_NARRATOR + AWAITING_INPUT, interactive=False) #, visible=False)
|
61 |
+
gr_n_turns_elapsed = gr.Textbox(value="0", interactive=False) #, visible=False)
|
62 |
+
gr_print_output = gr.Textbox(label="", value=GAME_INTRO + AWAITING_INPUT, interactive=False)
|
63 |
+
gr_user_input = gr.Textbox(label="", value="", interactive=True)
|
64 |
+
gr_button1 = gr.Button(value="Run Next Turn")
|
65 |
+
|
66 |
+
gr_button1.click(fn=run_1_game_turn,
|
67 |
+
inputs=[gr_narrator_transcript, gr_n_turns_elapsed, gr_print_output, gr_user_input],
|
68 |
+
outputs=[gr_narrator_transcript, gr_n_turns_elapsed, gr_print_output, gr_user_input])
|
69 |
|
70 |
demo.launch()
|