Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,34 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
return "Datos insuficientes"
|
| 9 |
-
return "Bien" if ventas[-1] > ventas[-2] else "Mal"
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
return crecimiento_ventas(ventas_str)
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|