Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
|
| 4 |
+
# Step 1: Load the fine-tuned model and tokenizer
|
| 5 |
+
MODEL_NAME = "ridahabbash/AccR4" # Replace with your model's Hub ID
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
| 8 |
+
|
| 9 |
+
# Step 2: Define the prediction function
|
| 10 |
+
def generate_report(prompt):
|
| 11 |
+
# Tokenize input
|
| 12 |
+
inputs = tokenizer(prompt, return_tensors="pt", max_length=512, truncation=True)
|
| 13 |
+
|
| 14 |
+
# Generate output
|
| 15 |
+
outputs = model.generate(**inputs, max_length=128)
|
| 16 |
+
|
| 17 |
+
# Decode and return the result
|
| 18 |
+
report = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 19 |
+
return report
|
| 20 |
+
|
| 21 |
+
# Step 3: Create the Streamlit interface
|
| 22 |
+
st.title("Accounting Report Generator")
|
| 23 |
+
st.markdown("Enter a ledger entry below, and the model will generate a report.")
|
| 24 |
+
|
| 25 |
+
# Input textbox
|
| 26 |
+
prompt = st.text_area("Ledger Entry", placeholder="Enter ledger details here...")
|
| 27 |
+
|
| 28 |
+
# Generate button
|
| 29 |
+
if st.button("Generate Report"):
|
| 30 |
+
if prompt.strip() == "":
|
| 31 |
+
st.error("Please enter a valid ledger entry.")
|
| 32 |
+
else:
|
| 33 |
+
# Generate report
|
| 34 |
+
with st.spinner("Generating report..."):
|
| 35 |
+
report = generate_report(prompt)
|
| 36 |
+
# Display the report
|
| 37 |
+
st.success("Report generated successfully!")
|
| 38 |
+
st.subheader("Generated Report:")
|
| 39 |
+
st.write(report)
|
| 40 |
+
|
| 41 |
+
|