Spaces:
Running
Running
Merge pull request #2 from evegarcianz/basic_version
Browse files- LLM_openai.py +5 -4
- app.py +10 -5
- dataframe_processing.py +9 -9
LLM_openai.py
CHANGED
@@ -12,10 +12,11 @@ def expense_classifier(expense):
|
|
12 |
"content": [
|
13 |
{
|
14 |
"type": "text",
|
15 |
-
"text": """
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
19 |
"""
|
20 |
}
|
21 |
]
|
|
|
12 |
"content": [
|
13 |
{
|
14 |
"type": "text",
|
15 |
+
"text": """Eres un asistente contable muy eficiente.
|
16 |
+
El usuario ingresar谩 un gasto y t煤 lo clasificar谩as en una categoria general de las siguientes:
|
17 |
+
[insumo, gasto fijo, sueldo].
|
18 |
+
Por favor s贸lo la categoria como respuesta.
|
19 |
+
|
20 |
"""
|
21 |
}
|
22 |
]
|
app.py
CHANGED
@@ -20,6 +20,7 @@ spreadsheet = gc.open("Snackers_spreadsheet").sheet1
|
|
20 |
def update_spend_from_image(img):
|
21 |
##This processes the image
|
22 |
extracted_dictionay_from_image=process_image(img)
|
|
|
23 |
total_from_receipt=extracted_dictionay_from_image['total']
|
24 |
concept_from_receipt=extracted_dictionay_from_image['purchase_summary']
|
25 |
shop_type=extracted_dictionay_from_image['store_type']
|
@@ -29,18 +30,18 @@ def update_spend_from_image(img):
|
|
29 |
concept_and_shop=concept_from_receipt+" from "+shop_type+f" ({shop_name})"
|
30 |
|
31 |
##The function update_spend in the line below only takes a string and float
|
32 |
-
category, day_month, todays_amount, current_week_amount , fig, fig2, fig3=update_spend(
|
33 |
|
34 |
return category, day_month, todays_amount, current_week_amount , fig, fig2, fig3
|
35 |
|
36 |
|
37 |
|
38 |
-
def update_spend(concept, amount, items_from_receipt=None):
|
39 |
category=expense_classifier(concept)
|
40 |
today = datetime.date.today()
|
41 |
|
42 |
# Append a new row
|
43 |
-
spreadsheet.append_row([str(today), concept,float(amount),category, items_from_receipt ])
|
44 |
|
45 |
day_month, todays_amount, current_week_amount , fig, fig2, fig3=dataframe_process(spreadsheet)
|
46 |
return category, day_month, todays_amount, current_week_amount , fig, fig2, fig3
|
@@ -63,9 +64,11 @@ with gr.Blocks() as demo:
|
|
63 |
|
64 |
with gr.Tab("Entrada manual"):
|
65 |
with gr.Row():
|
66 |
-
concept = gr.Textbox(label="
|
67 |
with gr.Row():
|
68 |
amount= gr.Textbox(label="Monto")
|
|
|
|
|
69 |
btn_manual = gr.Button("Ingresar gasto")
|
70 |
|
71 |
with gr.Tab("Cargar recibo"):
|
@@ -91,10 +94,12 @@ with gr.Blocks() as demo:
|
|
91 |
category_plot=gr.Plot()
|
92 |
|
93 |
|
94 |
-
btn_manual.click(fn=update_spend, inputs=[concept, amount], outputs=[expense_class,ui_date, expenses_today,expenses_this_week,
|
95 |
daily_plot,week_plot,category_plot])
|
|
|
96 |
btn_image.click(fn=update_spend_from_image, inputs=[input_image], outputs=[expense_class,ui_date, expenses_today,expenses_this_week,
|
97 |
daily_plot,week_plot,category_plot])
|
|
|
98 |
btn_show.click(fn=show_plots, inputs=[], outputs=[expense_class,ui_date, expenses_today,expenses_this_week,
|
99 |
daily_plot,week_plot,category_plot])
|
100 |
|
|
|
20 |
def update_spend_from_image(img):
|
21 |
##This processes the image
|
22 |
extracted_dictionay_from_image=process_image(img)
|
23 |
+
|
24 |
total_from_receipt=extracted_dictionay_from_image['total']
|
25 |
concept_from_receipt=extracted_dictionay_from_image['purchase_summary']
|
26 |
shop_type=extracted_dictionay_from_image['store_type']
|
|
|
30 |
concept_and_shop=concept_from_receipt+" from "+shop_type+f" ({shop_name})"
|
31 |
|
32 |
##The function update_spend in the line below only takes a string and float
|
33 |
+
category, day_month, todays_amount, current_week_amount , fig, fig2, fig3=update_spend(shop_name, total_from_receipt, concept_and_shop,receipt_items)
|
34 |
|
35 |
return category, day_month, todays_amount, current_week_amount , fig, fig2, fig3
|
36 |
|
37 |
|
38 |
|
39 |
+
def update_spend(concept, amount, description ,items_from_receipt=None):
|
40 |
category=expense_classifier(concept)
|
41 |
today = datetime.date.today()
|
42 |
|
43 |
# Append a new row
|
44 |
+
spreadsheet.append_row([str(today), concept,float(amount), description,category, items_from_receipt ])
|
45 |
|
46 |
day_month, todays_amount, current_week_amount , fig, fig2, fig3=dataframe_process(spreadsheet)
|
47 |
return category, day_month, todays_amount, current_week_amount , fig, fig2, fig3
|
|
|
64 |
|
65 |
with gr.Tab("Entrada manual"):
|
66 |
with gr.Row():
|
67 |
+
concept = gr.Textbox(label="Cliente o Proveedor")
|
68 |
with gr.Row():
|
69 |
amount= gr.Textbox(label="Monto")
|
70 |
+
with gr.Row():
|
71 |
+
description= gr.Textbox(label="descripcion")
|
72 |
btn_manual = gr.Button("Ingresar gasto")
|
73 |
|
74 |
with gr.Tab("Cargar recibo"):
|
|
|
94 |
category_plot=gr.Plot()
|
95 |
|
96 |
|
97 |
+
btn_manual.click(fn=update_spend, inputs=[concept, amount, description ,], outputs=[expense_class,ui_date, expenses_today,expenses_this_week,
|
98 |
daily_plot,week_plot,category_plot])
|
99 |
+
|
100 |
btn_image.click(fn=update_spend_from_image, inputs=[input_image], outputs=[expense_class,ui_date, expenses_today,expenses_this_week,
|
101 |
daily_plot,week_plot,category_plot])
|
102 |
+
|
103 |
btn_show.click(fn=show_plots, inputs=[], outputs=[expense_class,ui_date, expenses_today,expenses_this_week,
|
104 |
daily_plot,week_plot,category_plot])
|
105 |
|
dataframe_processing.py
CHANGED
@@ -5,26 +5,26 @@ from utils import create_plot, create_barplot
|
|
5 |
def dataframe_process(sheet):
|
6 |
# Create dataframe
|
7 |
df = pd.DataFrame(sheet.get_all_records())
|
8 |
-
df['
|
9 |
-
df['week'] = df['
|
10 |
|
11 |
#Per day
|
12 |
-
daily_total=df[['
|
13 |
-
daily_total['month_day'] = daily_total['
|
14 |
|
15 |
|
16 |
|
17 |
fig = create_plot(daily_total['month_day'],daily_total['amount'])
|
18 |
|
19 |
-
daily_total=daily_total.sort_values(by='
|
20 |
-
daily_total=daily_total[['
|
21 |
todays_amount=daily_total.iloc[0]['amount']
|
22 |
-
todays_date=daily_total.iloc[0]['
|
23 |
day_month = todays_date.strftime('%m-%d-%Y')
|
24 |
|
25 |
#Per week
|
26 |
# Group by 'week' and sum the values
|
27 |
-
weekly_df = df[['
|
28 |
weekly_df=weekly_df.sort_values(by='week', ascending=True)
|
29 |
# weekly_df.index=weekly_df.index.strftime('%m-%d')
|
30 |
current_week_amount="{:.2f}".format(weekly_df.iloc[-1]['amount'])
|
@@ -35,7 +35,7 @@ def dataframe_process(sheet):
|
|
35 |
|
36 |
|
37 |
#Per category
|
38 |
-
expenses_per_category=df[['
|
39 |
expenses_per_category=expenses_per_category.sort_values(by='amount', ascending=False)
|
40 |
fig3 = create_barplot(expenses_per_category['category'],expenses_per_category['amount'],"categoria","monto","gasto por categoria")
|
41 |
|
|
|
5 |
def dataframe_process(sheet):
|
6 |
# Create dataframe
|
7 |
df = pd.DataFrame(sheet.get_all_records())
|
8 |
+
df['fecha'] = pd.to_datetime(df['fecha'])
|
9 |
+
df['week'] = df['fecha'].dt.to_period('W')
|
10 |
|
11 |
#Per day
|
12 |
+
daily_total=df[['cliente_proveedor','amount','category','fecha']].groupby('fecha').sum().reset_index()
|
13 |
+
daily_total['month_day'] = daily_total['fecha'].dt.strftime('%m-%d')
|
14 |
|
15 |
|
16 |
|
17 |
fig = create_plot(daily_total['month_day'],daily_total['amount'])
|
18 |
|
19 |
+
daily_total=daily_total.sort_values(by='fecha', ascending=False)
|
20 |
+
daily_total=daily_total[['fecha', 'amount']]
|
21 |
todays_amount=daily_total.iloc[0]['amount']
|
22 |
+
todays_date=daily_total.iloc[0]['fecha']
|
23 |
day_month = todays_date.strftime('%m-%d-%Y')
|
24 |
|
25 |
#Per week
|
26 |
# Group by 'week' and sum the values
|
27 |
+
weekly_df = df[['cliente_proveedor','amount','category','week']].groupby('week').sum().reset_index()
|
28 |
weekly_df=weekly_df.sort_values(by='week', ascending=True)
|
29 |
# weekly_df.index=weekly_df.index.strftime('%m-%d')
|
30 |
current_week_amount="{:.2f}".format(weekly_df.iloc[-1]['amount'])
|
|
|
35 |
|
36 |
|
37 |
#Per category
|
38 |
+
expenses_per_category=df[['cliente_proveedor','amount','category']].groupby('category').sum().reset_index()
|
39 |
expenses_per_category=expenses_per_category.sort_values(by='amount', ascending=False)
|
40 |
fig3 = create_barplot(expenses_per_category['category'],expenses_per_category['amount'],"categoria","monto","gasto por categoria")
|
41 |
|