Spaces:
Sleeping
Sleeping
Commit
·
f2ba8f4
1
Parent(s):
2bd545f
test
Browse files
app.py
CHANGED
@@ -1,75 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
|
4 |
-
def
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
def update_game(command, game_state):
|
16 |
-
PIPE_WIDTH = 3
|
17 |
-
GAME_HEIGHT = 5
|
18 |
-
GAP_SIZE = 2
|
19 |
-
|
20 |
-
if game_state['game_over'] or command == "start":
|
21 |
-
return initialize_game()
|
22 |
-
|
23 |
-
# Move bird based on command
|
24 |
-
game_state['bird_position'] += 1 if command.lower() != "flap" else -1
|
25 |
-
|
26 |
-
# Check bounds
|
27 |
-
if game_state['bird_position'] < 0 or game_state['bird_position'] >= GAME_HEIGHT:
|
28 |
-
game_state['game_over'] = True
|
29 |
-
return f"You hit the top/bottom! Game Over! Your score: {game_state['score']}", game_state
|
30 |
-
|
31 |
-
# Update pipe position
|
32 |
-
game_state['height'] = (game_state['height'] + 1) % (PIPE_WIDTH + GAME_HEIGHT)
|
33 |
-
|
34 |
-
# Check for collision or passing through the gap
|
35 |
-
if game_state['height'] == PIPE_WIDTH:
|
36 |
-
if game_state['bird_position'] not in range(game_state['gap_position'], game_state['gap_position'] + GAP_SIZE):
|
37 |
-
game_state['game_over'] = True
|
38 |
-
return f"You hit a pipe! Game Over! Your score: {game_state['score']}", game_state
|
39 |
-
else:
|
40 |
-
game_state['score'] += 1
|
41 |
-
game_state['gap_position'] = random.randint(0, GAME_HEIGHT - GAP_SIZE)
|
42 |
-
|
43 |
-
return get_game_state(game_state), game_state
|
44 |
-
|
45 |
-
def get_game_state(game_state):
|
46 |
-
PIPE_WIDTH = 3
|
47 |
-
GAME_HEIGHT = 5
|
48 |
-
GAP_SIZE = 2
|
49 |
-
display = "Score: {}\n".format(game_state['score'])
|
50 |
-
for i in range(GAME_HEIGHT):
|
51 |
-
line = ""
|
52 |
-
if game_state['height'] < PIPE_WIDTH and (i < game_state['gap_position'] or i >= game_state['gap_position'] + GAP_SIZE):
|
53 |
-
line += "|"
|
54 |
-
else:
|
55 |
-
line += " "
|
56 |
-
line += "B" if i == game_state['bird_position'] else "_"
|
57 |
-
line += "\n"
|
58 |
-
display += line
|
59 |
-
return display
|
60 |
|
61 |
iface = gr.Interface(
|
62 |
-
fn=
|
63 |
-
inputs=[
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
outputs=[
|
68 |
-
gr.Textbox(label="Game State"),
|
69 |
-
gr.State()
|
70 |
-
],
|
71 |
-
title="Simple Text-based Flappy Bird Game",
|
72 |
-
description="Use the dropdown to 'Start' the game or 'Flap' to move the bird up. Avoid the pipes!"
|
73 |
)
|
74 |
|
75 |
if __name__ == "__main__":
|
|
|
1 |
import gradio as gr
|
2 |
+
import time
|
3 |
+
|
4 |
+
def start_pomodoro(duration):
|
5 |
+
# This function will simulate a Pomodoro timer.
|
6 |
+
# Real asynchronous waiting or background tasks aren't feasible with Gradio in its current state,
|
7 |
+
# so we'll return a message instead of a real timer.
|
8 |
+
|
9 |
+
if duration == 25:
|
10 |
+
return "Pomodoro started! Work for 25 minutes."
|
11 |
+
elif duration == 5:
|
12 |
+
return "Short break started! Relax for 5 minutes."
|
13 |
+
else:
|
14 |
+
return "Long break started! Relax for 15 minutes."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
iface = gr.Interface(
|
17 |
+
fn=start_pomodoro,
|
18 |
+
inputs=gr.Dropdown(choices=[25, 5, 15], label="Select Duration (minutes)"),
|
19 |
+
outputs="text",
|
20 |
+
title="Simple Pomodoro Timer",
|
21 |
+
description="Select duration and start a Pomodoro timer. Currently, the timer is simulated; it doesn't count down in real-time."
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
)
|
23 |
|
24 |
if __name__ == "__main__":
|