Spaces:
Runtime error
Runtime error
Commit
·
61b2e8e
1
Parent(s):
ae5d47a
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,84 +1,18 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import random
|
| 3 |
-
from PIL import Image, ImageDraw
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
gravity = 3
|
| 8 |
-
flap_strength = -30
|
| 9 |
-
ground_position = 300
|
| 10 |
-
pipe_position = 500
|
| 11 |
-
pipe_gap = 200
|
| 12 |
-
pipe_height = 100
|
| 13 |
-
score = 0
|
| 14 |
-
game_over = False
|
| 15 |
-
screen_width, screen_height = 500, 350
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
img = Image.new('RGB', (screen_width, screen_height), 'white')
|
| 20 |
-
draw = ImageDraw.Draw(img)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
draw.ellipse([150, bird_position, 180, bird_position + 30], fill='blue')
|
| 24 |
-
|
| 25 |
-
# Draw pipes
|
| 26 |
-
draw.rectangle([pipe_position, 0, pipe_position + 30, pipe_height], fill='green')
|
| 27 |
-
draw.rectangle([pipe_position, pipe_height + pipe_gap, pipe_position + 30, screen_height], fill='green')
|
| 28 |
-
|
| 29 |
-
# Draw ground
|
| 30 |
-
draw.rectangle([0, ground_position, screen_width, screen_height], fill='brown')
|
| 31 |
-
|
| 32 |
-
return img
|
| 33 |
-
|
| 34 |
-
# Game Functions
|
| 35 |
-
def flap():
|
| 36 |
-
global bird_position, game_over
|
| 37 |
-
if not game_over:
|
| 38 |
-
bird_position += flap_strength
|
| 39 |
-
|
| 40 |
-
def update_game():
|
| 41 |
-
global bird_position, pipe_position, score, ground_position, game_over, pipe_height
|
| 42 |
-
if not game_over:
|
| 43 |
-
bird_position += gravity
|
| 44 |
-
pipe_position -= 5
|
| 45 |
-
|
| 46 |
-
if bird_position > ground_position:
|
| 47 |
-
bird_position = ground_position
|
| 48 |
-
game_over = True
|
| 49 |
-
|
| 50 |
-
if (150 < pipe_position < 190) and not (pipe_height < bird_position < pipe_height + pipe_gap):
|
| 51 |
-
game_over = True
|
| 52 |
-
|
| 53 |
-
if pipe_position < 0:
|
| 54 |
-
score += 1
|
| 55 |
-
pipe_position = 500
|
| 56 |
-
pipe_height = random.randint(50, 250)
|
| 57 |
-
|
| 58 |
-
def reset_game():
|
| 59 |
-
global bird_position, pipe_position, score, game_over, pipe_height
|
| 60 |
-
bird_position = 250
|
| 61 |
-
pipe_position = 500
|
| 62 |
-
pipe_height = 100
|
| 63 |
-
score = 0
|
| 64 |
-
game_over = False
|
| 65 |
-
|
| 66 |
-
def game_output():
|
| 67 |
-
update_game()
|
| 68 |
-
return draw_game(), f"Score: {score}\n{'GAME OVER' if game_over else ''}"
|
| 69 |
-
|
| 70 |
-
# Gradio Interface
|
| 71 |
iface = gr.Interface(
|
| 72 |
-
fn=
|
| 73 |
-
inputs=
|
| 74 |
-
outputs=
|
| 75 |
-
|
| 76 |
-
allow_flagging="never",
|
| 77 |
-
manual_run=True
|
| 78 |
)
|
| 79 |
|
| 80 |
-
|
| 81 |
-
reset_button.click(fn=reset_game, inputs=None, outputs=None)
|
| 82 |
-
iface.add_component(reset_button)
|
| 83 |
-
|
| 84 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def process_input(input_value):
|
| 4 |
+
return f"Slider Value: {input_value}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# Create the slider component
|
| 7 |
+
slider = gr.components.Slider(minimum=0, maximum=1, step=0.01, label="Rotated Slider")
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# Define the interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
iface = gr.Interface(
|
| 11 |
+
fn=process_input,
|
| 12 |
+
inputs=slider,
|
| 13 |
+
outputs="text",
|
| 14 |
+
css=".slider_container { transform: rotate(30deg); }"
|
|
|
|
|
|
|
| 15 |
)
|
| 16 |
|
| 17 |
+
# Launch the interface
|
|
|
|
|
|
|
|
|
|
| 18 |
iface.launch()
|