Merlintxu commited on
Commit
e35bed9
1 Parent(s): 3448532

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -38
app.py CHANGED
@@ -52,9 +52,6 @@ def optimize_image(image, png_optimize, jpeg_quality, jpeg_resolution, webp_qual
52
  webp_lossy_img, f"WebP con pérdida: {webp_lossy_size:.2f} KB (diferencia: {-webp_lossy_diff:.2f} KB)", webp_lossy_output_path
53
  ]
54
 
55
- def download_image(file_path):
56
- return gr.File.update(value=file_path, label="Descargar", visible=True)
57
-
58
  with gr.Blocks() as demo:
59
  gr.Markdown("### Optimización de imágenes para la web")
60
 
@@ -65,42 +62,36 @@ with gr.Blocks() as demo:
65
  with gr.Column():
66
  optimized_output1 = gr.Image(label="Optimización sin pérdida")
67
  png_optimize = gr.Checkbox(label="Optimizar PNG", value=True)
68
- download_button1 = gr.Button("Descargar")
69
- download_file1 = gr.File(visible=False)
70
  optimized_size1 = gr.Text(value="", interactive=False, show_label=False)
71
 
72
  with gr.Column():
73
  optimized_output2 = gr.Image(label="Optimización con pérdida (JPEG)")
74
  jpeg_quality = gr.Slider(label="Calidad JPEG", minimum=10, maximum=100, value=50, step=1)
75
- download_button2 = gr.Button("Descargar")
76
- download_file2 = gr.File(visible=False)
77
  optimized_size2 = gr.Text(value="", interactive=False, show_label=False)
78
 
79
  with gr.Column():
80
  optimized_output3 = gr.Image(label="Reducción de resolución (JPEG)")
81
  jpeg_resolution = gr.Slider(label="Resolución JPEG (%)", minimum=10, maximum=100, value=50, step=1)
82
- download_button3 = gr.Button("Descargar")
83
- download_file3 = gr.File(visible=False)
84
  optimized_size3 = gr.Text(value="", interactive=False, show_label=False)
85
 
86
-
87
  with gr.Column():
88
  optimized_output4 = gr.Image(label="Optimización WebP con pérdida")
89
  webp_quality = gr.Slider(label="Calidad WebP", minimum=10, maximum=100, value=50, step=1)
90
- download_button4 = gr.Button("Descargar")
91
- download_file4 = gr.File(visible=False)
92
  optimized_size4 = gr.Text(value="", interactive=False, show_label=False)
93
 
94
-
95
  # Conectar cada control a la función de optimización
96
  optimize_button.click(
97
  fn=optimize_image,
98
  inputs=[image_input, png_optimize, jpeg_quality, jpeg_resolution, webp_quality],
99
  outputs=[
100
- optimized_output1, optimized_size1, download_file1,
101
- optimized_output2, optimized_size2, download_file2,
102
- optimized_output3, optimized_size3, download_file3,
103
- optimized_output4, optimized_size4, download_file4
104
  ]
105
  )
106
 
@@ -108,10 +99,10 @@ with gr.Blocks() as demo:
108
  fn=optimize_image,
109
  inputs=[image_input, png_optimize, jpeg_quality, jpeg_resolution, webp_quality],
110
  outputs=[
111
- optimized_output1, optimized_size1, download_file1,
112
- optimized_output2, optimized_size2, download_file2,
113
- optimized_output3, optimized_size3, download_file3,
114
- optimized_output4, optimized_size4, download_file4
115
  ]
116
  )
117
 
@@ -119,10 +110,10 @@ with gr.Blocks() as demo:
119
  fn=optimize_image,
120
  inputs=[image_input, png_optimize, jpeg_quality, jpeg_resolution, webp_quality],
121
  outputs=[
122
- optimized_output1, optimized_size1, download_file1,
123
- optimized_output2, optimized_size2, download_file2,
124
- optimized_output3, optimized_size3, download_file3,
125
- optimized_output4, optimized_size4, download_file4
126
  ]
127
  )
128
 
@@ -130,10 +121,10 @@ with gr.Blocks() as demo:
130
  fn=optimize_image,
131
  inputs=[image_input, png_optimize, jpeg_quality, jpeg_resolution, webp_quality],
132
  outputs=[
133
- optimized_output1, optimized_size1, download_file1,
134
- optimized_output2, optimized_size2, download_file2,
135
- optimized_output3, optimized_size3, download_file3,
136
- optimized_output4, optimized_size4, download_file4
137
  ]
138
  )
139
 
@@ -141,16 +132,11 @@ with gr.Blocks() as demo:
141
  fn=optimize_image,
142
  inputs=[image_input, png_optimize, jpeg_quality, jpeg_resolution, webp_quality],
143
  outputs=[
144
- optimized_output1, optimized_size1, download_file1,
145
- optimized_output2, optimized_size2, download_file2,
146
- optimized_output3, optimized_size3, download_file3,
147
- optimized_output4, optimized_size4, download_file4
148
  ]
149
  )
150
 
151
- download_button1.click(download_image, inputs=download_file1, outputs=download_file1)
152
- download_button2.click(download_image, inputs=download_file2, outputs=download_file2)
153
- download_button3.click(download_image, inputs=download_file3, outputs=download_file3)
154
- download_button4.click(download_image, inputs=download_file4, outputs=download_file4)
155
-
156
  demo.launch()
 
52
  webp_lossy_img, f"WebP con pérdida: {webp_lossy_size:.2f} KB (diferencia: {-webp_lossy_diff:.2f} KB)", webp_lossy_output_path
53
  ]
54
 
 
 
 
55
  with gr.Blocks() as demo:
56
  gr.Markdown("### Optimización de imágenes para la web")
57
 
 
62
  with gr.Column():
63
  optimized_output1 = gr.Image(label="Optimización sin pérdida")
64
  png_optimize = gr.Checkbox(label="Optimizar PNG", value=True)
65
+ download_button1 = gr.File(label="Descargar", visible=True)
 
66
  optimized_size1 = gr.Text(value="", interactive=False, show_label=False)
67
 
68
  with gr.Column():
69
  optimized_output2 = gr.Image(label="Optimización con pérdida (JPEG)")
70
  jpeg_quality = gr.Slider(label="Calidad JPEG", minimum=10, maximum=100, value=50, step=1)
71
+ download_button2 = gr.File(label="Descargar", visible=True)
 
72
  optimized_size2 = gr.Text(value="", interactive=False, show_label=False)
73
 
74
  with gr.Column():
75
  optimized_output3 = gr.Image(label="Reducción de resolución (JPEG)")
76
  jpeg_resolution = gr.Slider(label="Resolución JPEG (%)", minimum=10, maximum=100, value=50, step=1)
77
+ download_button3 = gr.File(label="Descargar", visible=True)
 
78
  optimized_size3 = gr.Text(value="", interactive=False, show_label=False)
79
 
 
80
  with gr.Column():
81
  optimized_output4 = gr.Image(label="Optimización WebP con pérdida")
82
  webp_quality = gr.Slider(label="Calidad WebP", minimum=10, maximum=100, value=50, step=1)
83
+ download_button4 = gr.File(label="Descargar", visible=True)
 
84
  optimized_size4 = gr.Text(value="", interactive=False, show_label=False)
85
 
 
86
  # Conectar cada control a la función de optimización
87
  optimize_button.click(
88
  fn=optimize_image,
89
  inputs=[image_input, png_optimize, jpeg_quality, jpeg_resolution, webp_quality],
90
  outputs=[
91
+ optimized_output1, optimized_size1, download_button1,
92
+ optimized_output2, optimized_size2, download_button2,
93
+ optimized_output3, optimized_size3, download_button3,
94
+ optimized_output4, optimized_size4, download_button4
95
  ]
96
  )
97
 
 
99
  fn=optimize_image,
100
  inputs=[image_input, png_optimize, jpeg_quality, jpeg_resolution, webp_quality],
101
  outputs=[
102
+ optimized_output1, optimized_size1, download_button1,
103
+ optimized_output2, optimized_size2, download_button2,
104
+ optimized_output3, optimized_size3, download_button3,
105
+ optimized_output4, optimized_size4, download_button4
106
  ]
107
  )
108
 
 
110
  fn=optimize_image,
111
  inputs=[image_input, png_optimize, jpeg_quality, jpeg_resolution, webp_quality],
112
  outputs=[
113
+ optimized_output1, optimized_size1, download_button1,
114
+ optimized_output2, optimized_size2, download_button2,
115
+ optimized_output3, optimized_size3, download_button3,
116
+ optimized_output4, optimized_size4, download_button4
117
  ]
118
  )
119
 
 
121
  fn=optimize_image,
122
  inputs=[image_input, png_optimize, jpeg_quality, jpeg_resolution, webp_quality],
123
  outputs=[
124
+ optimized_output1, optimized_size1, download_button1,
125
+ optimized_output2, optimized_size2, download_button2,
126
+ optimized_output3, optimized_size3, download_button3,
127
+ optimized_output4, optimized_size4, download_button4
128
  ]
129
  )
130
 
 
132
  fn=optimize_image,
133
  inputs=[image_input, png_optimize, jpeg_quality, jpeg_resolution, webp_quality],
134
  outputs=[
135
+ optimized_output1, optimized_size1, download_button1,
136
+ optimized_output2, optimized_size2, download_button2,
137
+ optimized_output3, optimized_size3, download_button3,
138
+ optimized_output4, optimized_size4, download_button4
139
  ]
140
  )
141
 
 
 
 
 
 
142
  demo.launch()