Spaces:
Sleeping
Sleeping
Update app.py
Browse files132 unmodified lines133134135136137138139140141142143144145146147148149150151152153154136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178157158159160161162163164165166167168169170171172173174175176177178179180181182183179180181182183132 unmodified lines
submit = st.button("Submit")
if submit: st.session_state.submit = True
if st.session_state.submit: if uploaded_files: client = OpenAI(api_key=openai_api_key)
# test api key try: response = client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Say this is a test"} ] ) except: st.session_state.error = "OpenAI API key is invalid" st.session_state.success = None if submit: st.session_state.submit = True if st.session_state.submit: if uploaded_files: client = OpenAI(api_key=openai_api_key) # test api key try: response = client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "Say this is a test"} ] ) except: st.session_state.error = "OpenAI API key is invalid" st.session_state.success = None st.session_state.submit = False st.rerun() textify_output = read_and_textify_advanced(uploaded_files, sentence_chunks) df = pd.DataFrame(textify_output) df.columns = ['context'] if question_protocol == "": question_protocol = "Write questions based on the text" df['questions'] = df.apply(lambda row: get_questions(row['context'], question_protocol), axis=1) if answer_protocol == "": answer_protocol = "Write answers based on the text" df['answers'] = df.apply(lambda row: get_answers(row, answer_protocol), axis=1) df = df.drop('context', axis=1) csv = df.to_csv(index=False).encode('utf-8') st.session_state.error = "" st.session_state.success = csv st.session_state.submit = False st.rerun() textify_output = read_and_textify_advanced(uploaded_files, sentence_chunks) df = pd.DataFrame(textify_output) df.columns = ['context']
if question_protocol == "": question_protocol = "Write questions based on the text" df['questions'] = df.apply(lambda row: get_questions(row['context'], question_protocol), axis=1)
if answer_protocol == "": answer_protocol = "Write answers based on the text" df['answers'] = df.apply(lambda row: get_answers(row, answer_protocol), axis=1)
df = df.drop('context', axis=1)
csv = df.to_csv(index=False).encode('utf-8') st.session_state.error = "" st.session_state.success = csv st.session_state.submit = False st.rerun() else: st.session_state.error = "Please upload at least 1 PDF" st.session_state.success = None st.session_state.submit = False st.rerun() else: st.session_state.error = "Please upload at least 1 PDF" st.session_state.success = None st.session_state.submit = False st.rerun()app.py+46-46