Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,17 @@
|
|
| 1 |
-
import pygame
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
def
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
pygame.display.flip()
|
| 21 |
-
|
| 22 |
-
pygame.quit()
|
| 23 |
-
|
| 24 |
-
# GradioでUIを作成しPygameゲームをラップする
|
| 25 |
-
iface = gr.Interface(fn=run_game,
|
| 26 |
-
live=True,
|
| 27 |
-
show_input=False,
|
| 28 |
-
show_output=True,
|
| 29 |
-
capture_session=True)
|
| 30 |
-
|
| 31 |
-
iface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
|
| 4 |
+
def resize_image(image):
|
| 5 |
+
print(f"width:{image.width},height:{image.height}")
|
| 6 |
+
new_width=360
|
| 7 |
+
new_height=image.height*new_width//image.width
|
| 8 |
+
image = image.resize((new_width, new_height), Image.LANCZOS)
|
| 9 |
+
image = image.convert('1')
|
| 10 |
+
image.save("download.png", 'PNG', quality=95, dpi=[300,300], bits=1)
|
| 11 |
+
return "download.png"
|
| 12 |
+
|
| 13 |
+
iface = gr.Interface(fn=resize_image,
|
| 14 |
+
inputs=[gr.Image(type="pil")],
|
| 15 |
+
outputs="file")
|
| 16 |
+
|
| 17 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|