juyam commited on
Commit
3cdd5bd
·
1 Parent(s): ad4f85a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -30
app.py CHANGED
@@ -1,31 +1,17 @@
1
- import pygame
2
  import gradio as gr
3
-
4
- # Pygameのゲームコード
5
- def run_game():
6
- pygame.init()
7
-
8
- # initialization here
9
-
10
- running = True
11
- while running:
12
- for event in pygame.event.get():
13
- if event.type == pygame.QUIT:
14
- running = False
15
-
16
- # loop
17
-
18
- # update
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()