Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
import uuid
|
| 6 |
+
|
| 7 |
+
# Initialize Hugging Face pipeline
|
| 8 |
+
prompt_generator = pipeline("text-generation", model="gpt2")
|
| 9 |
+
|
| 10 |
+
# Basic structure for storing transactions
|
| 11 |
+
if 'transactions' not in st.session_state:
|
| 12 |
+
st.session_state.transactions = []
|
| 13 |
+
|
| 14 |
+
# App Title
|
| 15 |
+
st.title("AI Prompt-based ERP System")
|
| 16 |
+
|
| 17 |
+
# User onboarding and initial configuration
|
| 18 |
+
st.sidebar.header("Business Setup")
|
| 19 |
+
company_name = st.sidebar.text_input("Company Name")
|
| 20 |
+
industry = st.sidebar.text_input("Industry")
|
| 21 |
+
|
| 22 |
+
if st.sidebar.button("Generate Chart of Accounts"):
|
| 23 |
+
coa_prompt = f"Generate a basic chart of accounts for a {industry} company named {company_name}."
|
| 24 |
+
coa = prompt_generator(coa_prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
|
| 25 |
+
st.sidebar.write("**Suggested Chart of Accounts:**")
|
| 26 |
+
st.sidebar.write(coa)
|
| 27 |
+
|
| 28 |
+
# Transaction input
|
| 29 |
+
st.header("Record a Transaction")
|
| 30 |
+
user_prompt = st.text_area("Describe your transaction (e.g., 'I paid $30,000 in shop tax today'):")
|
| 31 |
+
|
| 32 |
+
if st.button("Generate Accounting Entry") and user_prompt:
|
| 33 |
+
full_prompt = f"Create accounting entry from prompt: '{user_prompt}'"
|
| 34 |
+
generated_entry = prompt_generator(full_prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
|
| 35 |
+
|
| 36 |
+
# Generate unique transaction ID
|
| 37 |
+
transaction_id = str(uuid.uuid4())[:8]
|
| 38 |
+
|
| 39 |
+
# Record transaction
|
| 40 |
+
transaction = {
|
| 41 |
+
"id": transaction_id,
|
| 42 |
+
"date": datetime.now().strftime("%Y-%m-%d"),
|
| 43 |
+
"description": user_prompt,
|
| 44 |
+
"entry": generated_entry
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
st.session_state.transactions.append(transaction)
|
| 48 |
+
st.success(f"Transaction recorded with ID: {transaction_id}")
|
| 49 |
+
|
| 50 |
+
# Display recorded transactions
|
| 51 |
+
st.header("Transaction Records")
|
| 52 |
+
if st.session_state.transactions:
|
| 53 |
+
for trans in st.session_state.transactions:
|
| 54 |
+
st.subheader(f"Transaction ID: {trans['id']}")
|
| 55 |
+
st.write(f"**Date:** {trans['date']}")
|
| 56 |
+
st.write(f"**Description:** {trans['description']}")
|
| 57 |
+
st.write(f"**Generated Entry:** {trans['entry']}")
|
| 58 |
+
st.markdown("---")
|
| 59 |
+
else:
|
| 60 |
+
st.write("No transactions recorded yet.")
|
| 61 |
+
|
| 62 |
+
# Option to clear transactions
|
| 63 |
+
if st.button("Clear All Transactions"):
|
| 64 |
+
st.session_state.transactions.clear()
|
| 65 |
+
st.warning("All transactions cleared.")
|