Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
def calcola_budget(testo):
|
| 5 |
+
righe = testo.lower().split(",")
|
| 6 |
+
entrate, uscite = [], []
|
| 7 |
+
totale_entrate, totale_uscite = 0, 0
|
| 8 |
+
|
| 9 |
+
for riga in righe:
|
| 10 |
+
match = re.search(r"([a-zàèéùìò ]+)\s*([\d\.]+)", riga.strip())
|
| 11 |
+
if match:
|
| 12 |
+
descrizione, valore = match.groups()
|
| 13 |
+
valore = float(valore)
|
| 14 |
+
if any(k in descrizione for k in ["stipendio", "bonus", "entrata", "vendita", "rimborso"]):
|
| 15 |
+
entrate.append((descrizione.strip(), valore))
|
| 16 |
+
totale_entrate += valore
|
| 17 |
+
else:
|
| 18 |
+
uscite.append((descrizione.strip(), valore))
|
| 19 |
+
totale_uscite += valore
|
| 20 |
+
|
| 21 |
+
saldo = totale_entrate - totale_uscite
|
| 22 |
+
|
| 23 |
+
riepilogo = f"📥 Entrate: {totale_entrate:.2f} €\n📤 Uscite: {totale_uscite:.2f} €\n💰 Saldo: {saldo:.2f} €\n\n"
|
| 24 |
+
riepilogo += "🔹 **Dettaglio Entrate**\n"
|
| 25 |
+
for e in entrate:
|
| 26 |
+
riepilogo += f"- {e[0].capitalize()}: {e[1]} €\n"
|
| 27 |
+
riepilogo += "\n🔸 **Dettaglio Uscite**\n"
|
| 28 |
+
for u in uscite:
|
| 29 |
+
riepilogo += f"- {u[0].capitalize()}: {u[1]} €\n"
|
| 30 |
+
|
| 31 |
+
return riepilogo
|
| 32 |
+
|
| 33 |
+
demo = gr.Interface(fn=calcola_budget,
|
| 34 |
+
inputs=gr.Textbox(lines=4, placeholder="Es. stipendio 1800, affitto 750, spesa 250"),
|
| 35 |
+
outputs="text",
|
| 36 |
+
title="Calcolo Entrate/Uscite Mensili",
|
| 37 |
+
description="Scrivi una lista veloce di entrate e uscite. Ti calcoliamo il saldo.")
|
| 38 |
+
|
| 39 |
+
demo.launch()
|