micole66 commited on
Commit
7c216bc
1 Parent(s): 84e5e74

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import random
4
+
5
+ # Card values and images
6
+ cards = {
7
+ 'Ace': 1,
8
+ '2': 2,
9
+ '3': 3,
10
+ '4': 4
11
+ }
12
+
13
+ card_images = {
14
+ 'Ace': "https://images.fineartamerica.com/images/artworkimages/mediumlarge/1/poker-playing-card-ace-diamond-miroslav-nemecek.jpg",
15
+ '2': "https://cdn.vectorstock.com/i/1000v/58/67/poker-playing-card-2-club-vector-8695867.jpg",
16
+ '3': "https://images.fineartamerica.com/images/artworkimages/mediumlarge/1/poker-playing-card-3-diamond-miroslav-nemecek.jpg",
17
+ '4': "https://images.fineartamerica.com/images/artworkimages/mediumlarge/1/poker-playing-card-4-spade-miroslav-nemecek.jpg"
18
+ }
19
+
20
+ def get_random_card():
21
+ return random.choice(list(cards.keys()))
22
+
23
+ def check_guess(current_card, next_card, guess):
24
+ current_value = cards[current_card]
25
+ next_value = cards[next_card]
26
+
27
+ if guess == "higher":
28
+ return next_value > current_value
29
+ elif guess == "lower":
30
+ return next_value < current_value
31
+ else: # same
32
+ return next_value == current_value
33
+
34
+ def play_game(choice):
35
+ current_card = get_random_card()
36
+ next_card = get_random_card()
37
+
38
+ result = check_guess(current_card, next_card, choice)
39
+
40
+ return (
41
+ card_images[current_card],
42
+ card_images[next_card],
43
+ "Correct!" if result else "Wrong!"
44
+ )
45
+
46
+ # Create Gradio interface
47
+ with gr.Blocks() as demo:
48
+ gr.Markdown("# Higher Lower Card Game")
49
+
50
+ with gr.Row():
51
+ current_card_image = gr.Image(label="Current Card")
52
+ next_card_image = gr.Image(label="Next Card")
53
+
54
+ with gr.Row():
55
+ higher_btn = gr.Button("Higher")
56
+ lower_btn = gr.Button("Lower")
57
+ same_btn = gr.Button("Same")
58
+
59
+ result_text = gr.Textbox(label="Result")
60
+
61
+ higher_btn.click(
62
+ fn=play_game,
63
+ inputs=[gr.Textbox(value="higher", visible=False)],
64
+ outputs=[current_card_image, next_card_image, result_text]
65
+ )
66
+
67
+ lower_btn.click(
68
+ fn=play_game,
69
+ inputs=[gr.Textbox(value="lower", visible=False)],
70
+ outputs=[current_card_image, next_card_image, result_text]
71
+ )
72
+
73
+ same_btn.click(
74
+ fn=play_game,
75
+ inputs=[gr.Textbox(value="same", visible=False)],
76
+ outputs=[current_card_image, next_card_image, result_text]
77
+ )
78
+
79
+ demo.launch()