Spaces:
Runtime error
Runtime error
Update Gradio app with multiple files
Browse files
app.py
CHANGED
|
@@ -224,7 +224,6 @@ def create_interface():
|
|
| 224 |
# Login section
|
| 225 |
with gr.Row():
|
| 226 |
with gr.Column(scale=1):
|
| 227 |
-
login_btn = gr.LoginButton()
|
| 228 |
user_info = gr.HTML("<p>🔐 Please login with Hugging Face to play</p>")
|
| 229 |
|
| 230 |
# Main game area (hidden until login)
|
|
@@ -310,39 +309,51 @@ def create_interface():
|
|
| 310 |
return (
|
| 311 |
gr.update(value=f"✅ Logged in as: {profile['name']}"),
|
| 312 |
gr.update(visible=True),
|
| 313 |
-
|
| 314 |
)
|
| 315 |
-
return gr.update(), gr.update(visible=False),
|
| 316 |
|
| 317 |
login_btn.click(
|
| 318 |
handle_login,
|
| 319 |
-
inputs=[],
|
| 320 |
outputs=[user_info, game_area, user_status]
|
| 321 |
)
|
| 322 |
|
| 323 |
create_box_btn.click(
|
| 324 |
create_user_box,
|
| 325 |
-
inputs=[
|
| 326 |
outputs=[create_result, user_status]
|
| 327 |
)
|
| 328 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
battle_system_btn.click(
|
| 330 |
-
|
| 331 |
outputs=[battle_result, battle_log, user_status]
|
| 332 |
)
|
| 333 |
|
| 334 |
battle_player_btn.click(
|
| 335 |
-
|
| 336 |
outputs=[battle_result, battle_log, user_status]
|
| 337 |
)
|
| 338 |
|
| 339 |
shop_btn.click(
|
| 340 |
-
|
| 341 |
outputs=[shop_display, shop_result]
|
| 342 |
)
|
| 343 |
|
| 344 |
buy_btn.click(
|
| 345 |
-
|
| 346 |
inputs=[item_choice_input],
|
| 347 |
outputs=[shop_result, shop_display]
|
| 348 |
)
|
|
@@ -353,7 +364,7 @@ def create_interface():
|
|
| 353 |
)
|
| 354 |
|
| 355 |
refresh_shop_btn.click(
|
| 356 |
-
|
| 357 |
outputs=[shop_display, shop_result]
|
| 358 |
)
|
| 359 |
|
|
@@ -364,6 +375,7 @@ if __name__ == "__main__":
|
|
| 364 |
demo.launch(
|
| 365 |
server_name="0.0.0.0",
|
| 366 |
server_port=7860,
|
| 367 |
-
share=
|
| 368 |
-
show_api=False
|
|
|
|
| 369 |
)
|
|
|
|
| 224 |
# Login section
|
| 225 |
with gr.Row():
|
| 226 |
with gr.Column(scale=1):
|
|
|
|
| 227 |
user_info = gr.HTML("<p>🔐 Please login with Hugging Face to play</p>")
|
| 228 |
|
| 229 |
# Main game area (hidden until login)
|
|
|
|
| 309 |
return (
|
| 310 |
gr.update(value=f"✅ Logged in as: {profile['name']}"),
|
| 311 |
gr.update(visible=True),
|
| 312 |
+
get_user_status(user_id) if user_id else "No box created yet"
|
| 313 |
)
|
| 314 |
+
return gr.update(), gr.update(visible=False), "No box created yet"
|
| 315 |
|
| 316 |
login_btn.click(
|
| 317 |
handle_login,
|
| 318 |
+
inputs=[login_btn],
|
| 319 |
outputs=[user_info, game_area, user_status]
|
| 320 |
)
|
| 321 |
|
| 322 |
create_box_btn.click(
|
| 323 |
create_user_box,
|
| 324 |
+
inputs=[box_name_input],
|
| 325 |
outputs=[create_result, user_status]
|
| 326 |
)
|
| 327 |
|
| 328 |
+
def battle_system():
|
| 329 |
+
return battle_opponent("demo_user")
|
| 330 |
+
|
| 331 |
+
def battle_player():
|
| 332 |
+
return battle_opponent("demo_user", "player")
|
| 333 |
+
|
| 334 |
+
def show_shop_demo():
|
| 335 |
+
return show_shop("demo_user")
|
| 336 |
+
|
| 337 |
+
def buy_item_demo(choice):
|
| 338 |
+
return buy_item("demo_user", choice)
|
| 339 |
+
|
| 340 |
battle_system_btn.click(
|
| 341 |
+
battle_system,
|
| 342 |
outputs=[battle_result, battle_log, user_status]
|
| 343 |
)
|
| 344 |
|
| 345 |
battle_player_btn.click(
|
| 346 |
+
battle_player,
|
| 347 |
outputs=[battle_result, battle_log, user_status]
|
| 348 |
)
|
| 349 |
|
| 350 |
shop_btn.click(
|
| 351 |
+
show_shop_demo,
|
| 352 |
outputs=[shop_display, shop_result]
|
| 353 |
)
|
| 354 |
|
| 355 |
buy_btn.click(
|
| 356 |
+
buy_item_demo,
|
| 357 |
inputs=[item_choice_input],
|
| 358 |
outputs=[shop_result, shop_display]
|
| 359 |
)
|
|
|
|
| 364 |
)
|
| 365 |
|
| 366 |
refresh_shop_btn.click(
|
| 367 |
+
show_shop_demo,
|
| 368 |
outputs=[shop_display, shop_result]
|
| 369 |
)
|
| 370 |
|
|
|
|
| 375 |
demo.launch(
|
| 376 |
server_name="0.0.0.0",
|
| 377 |
server_port=7860,
|
| 378 |
+
share=False,
|
| 379 |
+
show_api=False,
|
| 380 |
+
prevent_thread_lock=False
|
| 381 |
)
|