Myloiose commited on
Commit
e10708c
·
verified ·
1 Parent(s): a4cc79a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -28
app.py CHANGED
@@ -1,34 +1,30 @@
1
  import gradio as gr
2
- import json
3
 
4
- def crecimiento_ventas_dict(input_json):
5
- # input_json es un string JSON porque gradio recibe texto
6
- try:
7
- data = json.loads(input_json)
8
- if "ventas" not in data:
9
- return json.dumps({"error": "Invalid input, missing 'ventas' key"})
10
-
11
- ventas = data["ventas"]
12
- # Ejemplo: ventas = [{"marca":"A", "talla":40, "precio":100, "numpares":2}, {...}, ...]
13
-
14
- # Para simplificar, vamos a sumar "precio * numpares" para el último y penúltimo
15
- if len(ventas) < 2:
16
- return json.dumps({"error": "Datos insuficientes"})
17
-
18
- total_ultimo = ventas[-1]["precio"] * ventas[-1]["numpares"]
19
- total_penultimo = ventas[-2]["precio"] * ventas[-2]["numpares"]
20
-
21
- resultado = "Bien" if total_ultimo > total_penultimo else "Mal"
22
-
23
- return json.dumps({"result": resultado})
24
-
25
- except Exception as e:
26
- return json.dumps({"error": str(e)})
27
 
28
  iface = gr.Interface(
29
- fn=crecimiento_ventas_dict,
30
- inputs=gr.Textbox(lines=10, placeholder='{"ventas":[{"marca":"A","talla":40,"precio":100,"numpares":2}, ...]}'),
31
- outputs="text"
 
 
32
  )
33
 
34
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
 
1
  import gradio as gr
 
2
 
3
+ def analizar_ventas(ventas_texto):
4
+ lineas = ventas_texto.strip().split("\n")
5
+ total = 0
6
+ for linea in lineas:
7
+ try:
8
+ partes = linea.split("-")
9
+ precio_x_cantidad = partes[1].strip()
10
+ precio, num_pares = precio_x_cantidad.split("x")
11
+ precio = float(precio.strip())
12
+ num_pares = int(num_pares.strip())
13
+ total += precio * num_pares
14
+ except:
15
+ pass
16
+ if total > 1000:
17
+ return "Bien"
18
+ else:
19
+ return "Mal"
 
 
 
 
 
 
20
 
21
  iface = gr.Interface(
22
+ fn=analizar_ventas,
23
+ inputs=gr.Textbox(lines=10, placeholder="Marca Talla - Precio x NumPares\nEjemplo:\nNike 38 - 150 x 2"),
24
+ outputs="text",
25
+ title="Análisis de crecimiento de ventas",
26
+ description="Ingresa las ventas para saber si el crecimiento es Bien o Mal"
27
  )
28
 
29
+ if __name__ == "__main__":
30
+ iface.launch()