ikerua commited on
Commit
0f8398d
·
1 Parent(s): 2cccbaa

huggingface interface update

Browse files
Files changed (1) hide show
  1. app.py +24 -24
app.py CHANGED
@@ -13,7 +13,7 @@ def solicitar_prediccion(image_path):
13
  Envía la imagen al endpoint /predict
14
  """
15
  if image_path is None:
16
- return "Por favor, sube una imagen primero."
17
 
18
  try:
19
  # Abrimos la imagen en modo binario para enviarla
@@ -25,12 +25,12 @@ def solicitar_prediccion(image_path):
25
  data = response.json()
26
 
27
  # Devolvemos la predicción
28
- return f"Predicción: {data.get('prediction')}"
29
 
30
  except requests.exceptions.RequestException as e:
31
- return f"Error en la conexión con la API: {str(e)}"
32
  except Exception as e:
33
- return f"Error desconocido: {str(e)}"
34
 
35
  def solicitar_resize(image_path, width, height):
36
  """
@@ -42,7 +42,7 @@ def solicitar_resize(image_path, width, height):
42
  try:
43
  # Validar inputs
44
  if width <= 0 or height <= 0:
45
- print("El ancho y alto deben ser positivos.")
46
  return None
47
 
48
  payload = {"width": int(width), "height": int(height)}
@@ -66,39 +66,39 @@ def solicitar_resize(image_path, width, height):
66
 
67
  # --- Construcción de la Interfaz con Blocks ---
68
  with gr.Blocks(title="Predictor & Resizer API Client") as demo:
69
- gr.Markdown("# Cliente para API de Imágenes")
70
- gr.Markdown("Sube una imagen y elige si quieres obtener una predicción o redimensionarla.")
71
 
72
  with gr.Row():
73
- # Columna Izquierda: Entrada
74
  with gr.Column():
75
- gr.Markdown("### 1. Entrada")
76
  # Selector de imágenes. 'type="filepath"' guarda la imagen temporalmente y nos da la ruta
77
- input_image = gr.Image(label="Sube tu imagen", type="filepath")
78
 
79
- # Columna Derecha: Acciones
80
  with gr.Column():
81
 
82
- # --- Sección de Predicción ---
83
- gr.Markdown("### 2. Predicción")
84
- predict_btn = gr.Button("🔍 Obtener Predicción", variant="primary")
85
- predict_output = gr.Textbox(label="Resultado de la API")
86
 
87
  # CORRECCIÓN AQUÍ: gr.HTML en mayúsculas
88
  gr.HTML("<hr>")
89
 
90
- # --- Sección de Resize ---
91
- gr.Markdown("### 3. Redimensionar (Resize)")
92
  with gr.Row():
93
- w_input = gr.Number(label="Ancho (Width)", value=200, precision=0)
94
- h_input = gr.Number(label="Alto (Height)", value=200, precision=0)
95
 
96
- resize_btn = gr.Button("🖼️ Redimensionar Imagen")
97
- resize_output = gr.Image(label="Imagen Redimensionada")
98
 
99
- # --- Conectar la lógica ---
100
 
101
- # Botón Predicción
102
  predict_btn.click(
103
  fn=solicitar_prediccion,
104
  inputs=[input_image],
@@ -112,6 +112,6 @@ with gr.Blocks(title="Predictor & Resizer API Client") as demo:
112
  outputs=resize_output
113
  )
114
 
115
- # Lanzar la aplicación
116
  if __name__ == "__main__":
117
  demo.launch()
 
13
  Envía la imagen al endpoint /predict
14
  """
15
  if image_path is None:
16
+ return "You must upload an image first."
17
 
18
  try:
19
  # Abrimos la imagen en modo binario para enviarla
 
25
  data = response.json()
26
 
27
  # Devolvemos la predicción
28
+ return f"Prediction: {data.get('prediction')}"
29
 
30
  except requests.exceptions.RequestException as e:
31
+ return f"Error connecting to the API: {str(e)}"
32
  except Exception as e:
33
+ return f"Unknown error: {str(e)}"
34
 
35
  def solicitar_resize(image_path, width, height):
36
  """
 
42
  try:
43
  # Validar inputs
44
  if width <= 0 or height <= 0:
45
+ print("Width and height must be positive.")
46
  return None
47
 
48
  payload = {"width": int(width), "height": int(height)}
 
66
 
67
  # --- Construcción de la Interfaz con Blocks ---
68
  with gr.Blocks(title="Predictor & Resizer API Client") as demo:
69
+ gr.Markdown("# Image API Client")
70
+ gr.Markdown("Upload an image and choose whether you want to get a prediction or resize it.")
71
 
72
  with gr.Row():
73
+ # Left Column: Input
74
  with gr.Column():
75
+ gr.Markdown("### 1. Input Image")
76
  # Selector de imágenes. 'type="filepath"' guarda la imagen temporalmente y nos da la ruta
77
+ input_image = gr.Image(label="Upload your image", type="filepath")
78
 
79
+ # Right Column: Actions
80
  with gr.Column():
81
 
82
+ # --- Prediction Section ---
83
+ gr.Markdown("### 2. Prediction")
84
+ predict_btn = gr.Button("🔍 Get Prediction", variant="primary")
85
+ predict_output = gr.Textbox(label="API Result")
86
 
87
  # CORRECCIÓN AQUÍ: gr.HTML en mayúsculas
88
  gr.HTML("<hr>")
89
 
90
+ # --- Resize Section ---
91
+ gr.Markdown("### 3. Resize Image")
92
  with gr.Row():
93
+ w_input = gr.Number(label="Width", value=200, precision=0)
94
+ h_input = gr.Number(label="Height", value=200, precision=0)
95
 
96
+ resize_btn = gr.Button("🖼️ Resize Image")
97
+ resize_output = gr.Image(label="Resized Image")
98
 
99
+ # --- Connect Logic ---
100
 
101
+ # Prediction Button
102
  predict_btn.click(
103
  fn=solicitar_prediccion,
104
  inputs=[input_image],
 
112
  outputs=resize_output
113
  )
114
 
115
+ # Launch the app
116
  if __name__ == "__main__":
117
  demo.launch()