import streamlit as st import re from transformers import pipeline st.title("Docs Answering AI App") st.write("---") st.write("### Give Doc Receipt Images to the AI and ask it whats on the receipt.") st.warning("**Powered by AI Language Models...**") st.write("---") import streamlit as st import pandas as pd from io import StringIO uploaded_file = st.file_uploader("Choose a file") if uploaded_file is not None: # To read file as bytes: bytes_data = uploaded_file.getvalue() st.write(bytes_data) # To convert to a string based IO: stringio = StringIO(uploaded_file.getvalue().decode("utf-8")) st.write(stringio) # To read file as string: string_data = stringio.read() st.write(string_data) # Can be used wherever a "file-like" object is accepted: dataframe = pd.read_csv(uploaded_file) st.write(dataframe) nlp = pipeline( "document-question-answering", model="impira/layoutlm-document-qa", ) res = nlp( "https://templates.invoicehome.com/invoice-template-us-neat-750px.png", "What is the invoice number?" ) st.write(res['answer']) # {'score': 0.9943977, 'answer': 'us-001', 'start': 15, 'end': 15} res = nlp( "https://miro.medium.com/max/787/1*iECQRIiOGTmEFLdWkVIH2g.jpeg", "What is the purchase amount?" ) st.write(res['answer'])