Hi, I am trying to make a streamlit app that will take input from users in the form of documents which will then use openai api to chat with the submitted documents. After submitting a document I get the error " AxiosError: Request failed with status code 403 ". I have good amount of credit in my account and no rate limit. I have asked on the Openai forum, and I was told that it was not a OpenAI API problem but a streamlit one.
import streamlit as st
import openai
import textract
import os
# Authenticate with OpenAI API
openai.api_key = '■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■GevsBmE0'
def chat_with_openai(document):
try:
response = openai.Completion.create(
engine="davinci",
prompt=document,
max_tokens=150
)
return response.choices[0].text.strip()
except openai.error.OpenAIError as e:
print(e)
return "Error occurred while processing the request."
def extract_text_from_file(uploaded_file):
# Save the uploaded file temporarily
with open("tempfile", "wb") as f:
f.write(uploaded_file.read())
# Use textract to extract text
text = textract.process("tempfile").decode('utf-8')
# Clean up and remove the temporary file
os.remove("tempfile")
return text
st.title('Chat with OpenAI using Document Submission')
uploaded_file = st.file_uploader("Upload your document:", type=['txt', 'pdf', 'docx', 'ppt'])
if uploaded_file:
document_text = extract_text_from_file(uploaded_file)
st.write("Document content:")
st.write(document_text)
if st.button('Chat with OpenAI'):
with st.spinner('Generating response...'):
response = chat_with_openai(document_text)
st.write("OpenAI's Response:")
st.write(response)