File size: 1,182 Bytes
f27d383
 
 
 
 
 
3200f7a
 
f27d383
12035f5
 
 
 
 
 
 
 
 
 
f27d383
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import os

st.title("AI Accountant - Prompt-Based ERP Entry")

model_path = "google/flan-t5-large"


# Check if tokenizer files exist β†’ if not, download them
required_files = ["tokenizer_config.json", "special_tokens_map.json", "spiece.model"]
missing_files = [f for f in required_files if not os.path.exists(os.path.join(model_path, f))]

if missing_files:
    st.info("Tokenizer files missing. Downloading tokenizer from base model...")
    tokenizer_dl = AutoTokenizer.from_pretrained("google/flan-t5-large")
    tokenizer_dl.save_pretrained(model_path)
    st.success("Tokenizer files downloaded.")

tokenizer = AutoTokenizer.from_pretrained(model_path, local_files_only=True)
model = AutoModelForSeq2SeqLM.from_pretrained(model_path, local_files_only=True)

user_input = st.text_area("Enter accounting transaction:")

if st.button("Generate Entry"):
    inputs = tokenizer(user_input, return_tensors="pt")
    outputs = model.generate(**inputs, max_new_tokens=128)
    result = tokenizer.decode(outputs[0], skip_special_tokens=True)
    st.json(eval(result))  # Convert JSON string to dict