Update app.py
Browse files
app.py
CHANGED
@@ -54,11 +54,10 @@ graph = builder.compile()
|
|
54 |
# Gradio UI function
|
55 |
def play_game(bet: int):
|
56 |
if bet < 1 or bet > 12:
|
57 |
-
return "Please enter a value between 1 and 12.", global_score["total"],
|
58 |
result = graph.invoke({"bet": bet, "result": "", "score": global_score["total"], "roll": 0})
|
59 |
-
dice_img = f"https://raw.githubusercontent.com/mnaylor7/dice-roll-animation/main/dice-{result['roll']}.gif" if 2 <= result['roll'] <= 12 else ""
|
60 |
game_history.append({"Bet": bet, "Roll": result["roll"], "Result": result["result"], "Score": result["score"]})
|
61 |
-
return result["result"], result["score"],
|
62 |
|
63 |
# Gradio Interface
|
64 |
with gr.Blocks() as demo:
|
@@ -69,10 +68,9 @@ with gr.Blocks() as demo:
|
|
69 |
with gr.Row():
|
70 |
result_output = gr.Textbox(label="Result")
|
71 |
score_output = gr.Number(label="Total Winnings", value=0, precision=0, interactive=False)
|
72 |
-
dice_display = gr.Image(label="Dice Roll Animation", visible=True)
|
73 |
history_table = gr.Dataframe(headers=["Bet", "Roll", "Result", "Score"], label="Game History", interactive=False)
|
74 |
|
75 |
-
play_button.click(play_game, inputs=[bet_input], outputs=[result_output, score_output,
|
76 |
|
77 |
if __name__ == "__main__":
|
78 |
demo.launch()
|
|
|
54 |
# Gradio UI function
|
55 |
def play_game(bet: int):
|
56 |
if bet < 1 or bet > 12:
|
57 |
+
return "Please enter a value between 1 and 12.", global_score["total"], []
|
58 |
result = graph.invoke({"bet": bet, "result": "", "score": global_score["total"], "roll": 0})
|
|
|
59 |
game_history.append({"Bet": bet, "Roll": result["roll"], "Result": result["result"], "Score": result["score"]})
|
60 |
+
return result["result"], result["score"], game_history[::-1]
|
61 |
|
62 |
# Gradio Interface
|
63 |
with gr.Blocks() as demo:
|
|
|
68 |
with gr.Row():
|
69 |
result_output = gr.Textbox(label="Result")
|
70 |
score_output = gr.Number(label="Total Winnings", value=0, precision=0, interactive=False)
|
|
|
71 |
history_table = gr.Dataframe(headers=["Bet", "Roll", "Result", "Score"], label="Game History", interactive=False)
|
72 |
|
73 |
+
play_button.click(play_game, inputs=[bet_input], outputs=[result_output, score_output, history_table])
|
74 |
|
75 |
if __name__ == "__main__":
|
76 |
demo.launch()
|