|
import streamlit as st |
|
import pandas as pd |
|
from huggingface_hub import InferenceClient |
|
|
|
|
|
client = InferenceClient(model="google/flan-t5-base") |
|
|
|
|
|
account_map = { |
|
"rent": "60001", |
|
"utilities": "60002", |
|
"cash": "10001", |
|
"bank": "10002" |
|
} |
|
|
|
|
|
segment = { |
|
"company": "01", |
|
"business_type": "102", |
|
"location": "001", |
|
"cost_center": "001", |
|
"future": "000" |
|
} |
|
|
|
def parse_prompt(prompt): |
|
response = client.text_generation(prompt=f"Extract accounting entry: {prompt}", max_new_tokens=50) |
|
return response |
|
|
|
def handle_gl_entry(prompt): |
|
|
|
if "rent" in prompt.lower(): |
|
account_name = "rent" |
|
amount = 500 |
|
else: |
|
account_name = "utilities" |
|
amount = 300 |
|
|
|
expense_account = account_map[account_name] |
|
cash_account = account_map["cash"] |
|
|
|
expense_account_code = f"{segment['company']}-{segment['business_type']}-{segment['location']}-{segment['cost_center']}-{expense_account}-{segment['future']}" |
|
cash_account_code = f"{segment['company']}-{segment['business_type']}-{segment['location']}-{segment['cost_center']}-{cash_account}-{segment['future']}" |
|
|
|
entry = pd.DataFrame([ |
|
{ |
|
"Date": "2025-04-01", |
|
"Description": f"{account_name.title()} Expense", |
|
"Account Code": expense_account_code, |
|
"Debit": amount, |
|
"Credit": 0 |
|
}, |
|
{ |
|
"Date": "2025-04-01", |
|
"Description": f"Payment for {account_name}", |
|
"Account Code": cash_account_code, |
|
"Debit": 0, |
|
"Credit": amount |
|
} |
|
]) |
|
return entry |
|
|
|
|
|
st.title("AI ERP Chat - MVP") |
|
prompt = st.text_input("Enter your accounting instruction:") |
|
|
|
if prompt: |
|
result = handle_gl_entry(prompt) |
|
st.dataframe(result) |
|
|