Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,13 +85,26 @@ def start_game():
|
|
| 85 |
|
| 86 |
def play_turn(human_response, loc, player, cur, custom_token, request: gr.Request):
|
| 87 |
"""Executes a single turn of the game loop based on user input."""
|
|
|
|
| 88 |
if not human_response.strip():
|
| 89 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
chosen_token = custom_token.strip() if custom_token and custom_token.strip() else (request.token if request else None)
|
| 92 |
|
| 93 |
if not chosen_token:
|
| 94 |
-
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
return
|
| 96 |
|
| 97 |
# 1. Process AI Model Response
|
|
@@ -109,7 +122,13 @@ def play_turn(human_response, loc, player, cur, custom_token, request: gr.Reques
|
|
| 109 |
temperature=0.7
|
| 110 |
)
|
| 111 |
except Exception as e:
|
| 112 |
-
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
return
|
| 114 |
|
| 115 |
processed_response = extract_after_final_answer(response.choices[0].message.content)
|
|
@@ -131,13 +150,27 @@ def play_turn(human_response, loc, player, cur, custom_token, request: gr.Reques
|
|
| 131 |
player.append_file(cur.filelist)
|
| 132 |
|
| 133 |
final_story = f"### ๐ {end_title}\n\n{end_desc}\n\n**The Journey Ends Here.**"
|
| 134 |
-
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
# Compile video now that game loop is terminating
|
| 136 |
video_file = compile_game_video(player)
|
| 137 |
|
| 138 |
if video_file:
|
| 139 |
final_story += "\n\n๐๏ธ **Your adventure video is ready below!**"
|
| 140 |
-
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
return
|
| 142 |
|
| 143 |
# 4. Advance to the next event normally
|
|
@@ -148,7 +181,14 @@ def play_turn(human_response, loc, player, cur, custom_token, request: gr.Reques
|
|
| 148 |
player.append_file(cur.filelist)
|
| 149 |
|
| 150 |
# Clear out the text box for the next turn while returning updated states
|
| 151 |
-
yield
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
# --------------------------------------------------------------------------
|
| 154 |
# LAYOUT DESIGN WITH INTEGRATED GALLERY BUILDER
|
|
|
|
| 85 |
|
| 86 |
def play_turn(human_response, loc, player, cur, custom_token, request: gr.Request):
|
| 87 |
"""Executes a single turn of the game loop based on user input."""
|
| 88 |
+
status = initial_player.get_attribute()
|
| 89 |
if not human_response.strip():
|
| 90 |
+
return (
|
| 91 |
+
"Please type an action to proceed!",
|
| 92 |
+
status['hp'], status['mp'], status['coin'],
|
| 93 |
+
cur.get_images(),
|
| 94 |
+
gr.update(), gr.update(),
|
| 95 |
+
loc, player, cur
|
| 96 |
+
)
|
| 97 |
|
| 98 |
chosen_token = custom_token.strip() if custom_token and custom_token.strip() else (request.token if request else None)
|
| 99 |
|
| 100 |
if not chosen_token:
|
| 101 |
+
yield (
|
| 102 |
+
"โ **Authentication Required:** Please enter a token above or use OAuth.",
|
| 103 |
+
status['hp'], status['mp'], status['coin'],
|
| 104 |
+
cur.get_images(),
|
| 105 |
+
gr.update(), gr.update(),
|
| 106 |
+
loc, player, cur
|
| 107 |
+
)
|
| 108 |
return
|
| 109 |
|
| 110 |
# 1. Process AI Model Response
|
|
|
|
| 122 |
temperature=0.7
|
| 123 |
)
|
| 124 |
except Exception as e:
|
| 125 |
+
yield (
|
| 126 |
+
f"Error calling API: {str(e)}",
|
| 127 |
+
status['hp'], status['mp'], status['coin'],
|
| 128 |
+
cur.get_images(),
|
| 129 |
+
gr.update(), gr.update(),
|
| 130 |
+
loc, player, cur
|
| 131 |
+
)
|
| 132 |
return
|
| 133 |
|
| 134 |
processed_response = extract_after_final_answer(response.choices[0].message.content)
|
|
|
|
| 150 |
player.append_file(cur.filelist)
|
| 151 |
|
| 152 |
final_story = f"### ๐ {end_title}\n\n{end_desc}\n\n**The Journey Ends Here.**"
|
| 153 |
+
yield (
|
| 154 |
+
final_story,
|
| 155 |
+
attribute['hp'], attribute['mp'], attribute['coin'],
|
| 156 |
+
next_image,
|
| 157 |
+
gr.update(visible=False),
|
| 158 |
+
gr.update(),
|
| 159 |
+
loc, player, cur
|
| 160 |
+
)
|
| 161 |
# Compile video now that game loop is terminating
|
| 162 |
video_file = compile_game_video(player)
|
| 163 |
|
| 164 |
if video_file:
|
| 165 |
final_story += "\n\n๐๏ธ **Your adventure video is ready below!**"
|
| 166 |
+
yield (
|
| 167 |
+
final_story,
|
| 168 |
+
attribute['hp'], attribute['mp'], attribute['coin'],
|
| 169 |
+
next_image,
|
| 170 |
+
gr.update(visible=False),
|
| 171 |
+
gr.update(visible=True, value=video_file),
|
| 172 |
+
loc, player, cur
|
| 173 |
+
)
|
| 174 |
return
|
| 175 |
|
| 176 |
# 4. Advance to the next event normally
|
|
|
|
| 181 |
player.append_file(cur.filelist)
|
| 182 |
|
| 183 |
# Clear out the text box for the next turn while returning updated states
|
| 184 |
+
yield (
|
| 185 |
+
next_story,
|
| 186 |
+
attribute['hp'], attribute['mp'], attribute['coin'],
|
| 187 |
+
next_image,
|
| 188 |
+
gr.update(value=""),
|
| 189 |
+
gr.update(),
|
| 190 |
+
loc, player, cur
|
| 191 |
+
)
|
| 192 |
|
| 193 |
# --------------------------------------------------------------------------
|
| 194 |
# LAYOUT DESIGN WITH INTEGRATED GALLERY BUILDER
|