pratikshahp commited on
Commit
0fa85db
·
verified ·
1 Parent(s): cd763ad

Rename exp-app.py to app.py

Browse files
Files changed (1) hide show
  1. exp-app.py → app.py +36 -35
exp-app.py → app.py RENAMED
@@ -4,7 +4,6 @@ from helper import load_world, save_world
4
  from together import Together
5
  from helper import get_together_api_key, load_env
6
 
7
-
8
  client = Together(api_key=get_together_api_key())
9
 
10
  world = load_world('./Kyropeia.json')
@@ -21,6 +20,7 @@ Write in second person. For example: "You are Jack" \
21
  Write in present tense. For example "You stand at..." \
22
  First describe the character and their backstory. \
23
  Then describes where they start and what they see around them."""
 
24
  world_info = f"""
25
  World: {world}
26
  Kingdom: {kingdom}
@@ -43,32 +43,13 @@ world['start'] = start
43
  #save_world(world, '../shared_data/Kyropeia.json') # preserve video version
44
  save_world(world, '.YourWorld_L1.json')
45
 
46
- demo = None # Added to allow restart
47
-
48
- def start_game(main_loop, share=False):
49
- global demo
50
- # If demo is already running, close it first
51
- if demo is not None:
52
- demo.close()
53
-
54
- demo = gr.ChatInterface(
55
- main_loop,
56
- chatbot=gr.Chatbot(
57
- height=250,
58
- placeholder="Type 'start game' to begin",
59
- type='messages' # Updated parameter for Gradio's chatbot messages
60
- ),
61
- textbox=gr.Textbox(
62
- placeholder="What do you do next?",
63
- container=False,
64
- scale=7
65
- ),
66
- title="AI RPG",
67
- theme="soft",
68
- examples=["Look around", "Continue the story"],
69
- cache_examples=False,
70
- )
71
- demo.launch(share=share, server_name="0.0.0.0")
72
 
73
  def run_action(message, history, game_state):
74
 
@@ -105,15 +86,35 @@ Your Character: {game_state['character']}"""
105
  result = model_output.choices[0].message.content
106
  return result
107
 
108
- game_state = {
109
- "world": world['description'],
110
- "kingdom": kingdom['description'],
111
- "town": town['description'],
112
- "character": character['description'],
113
- "start": start,
114
- }
115
-
116
  def main_loop(message, history):
117
  return run_action(message, history, game_state)
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  start_game(main_loop, True)
 
4
  from together import Together
5
  from helper import get_together_api_key, load_env
6
 
 
7
  client = Together(api_key=get_together_api_key())
8
 
9
  world = load_world('./Kyropeia.json')
 
20
  Write in present tense. For example "You stand at..." \
21
  First describe the character and their backstory. \
22
  Then describes where they start and what they see around them."""
23
+
24
  world_info = f"""
25
  World: {world}
26
  Kingdom: {kingdom}
 
43
  #save_world(world, '../shared_data/Kyropeia.json') # preserve video version
44
  save_world(world, '.YourWorld_L1.json')
45
 
46
+ game_state = {
47
+ "world": world['description'],
48
+ "kingdom": kingdom['description'],
49
+ "town": town['description'],
50
+ "character": character['description'],
51
+ "start": start,
52
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  def run_action(message, history, game_state):
55
 
 
86
  result = model_output.choices[0].message.content
87
  return result
88
 
 
 
 
 
 
 
 
 
89
  def main_loop(message, history):
90
  return run_action(message, history, game_state)
91
 
92
+ demo = None # Added to allow restart
93
+
94
+ def start_game(main_loop, share=False):
95
+ global demo
96
+ # If demo is already running, close it first
97
+ if demo is not None:
98
+ demo.close()
99
+
100
+ demo = gr.ChatInterface(
101
+ main_loop,
102
+ chatbot=gr.Chatbot(
103
+ height=250,
104
+ placeholder="Type 'start game' to begin",
105
+ type='messages' # Updated parameter for Gradio's chatbot messages
106
+ ),
107
+ textbox=gr.Textbox(
108
+ placeholder="What do you do next?",
109
+ container=False,
110
+ scale=7
111
+ ),
112
+ title="AI RPG",
113
+ theme="soft",
114
+ examples=["Look around", "Continue the story"],
115
+ cache_examples=False,
116
+ )
117
+ demo.launch(share=share, server_name="0.0.0.0")
118
+
119
+
120
  start_game(main_loop, True)