KeshavRa commited on
Commit
122a344
·
verified ·
1 Parent(s): d6c384f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -32
app.py CHANGED
@@ -114,36 +114,35 @@ openai_api_key = st.text_input("Enter your OpenAI API key", type="password")
114
  submit = st.button("Submit")
115
 
116
  if submit:
117
- try:
118
- client = OpenAI(api_key=openai_api_key)
 
 
 
 
119
 
120
- try:
121
- client.Model.list()
122
- except:
123
- st.error("OpenAI API key is invalid")
124
-
125
- if uploaded_files:
126
- textify_output = read_and_textify_advanced(uploaded_files, sentence_chunks)
127
-
128
- df = pd.DataFrame(textify_output)
129
- df.columns = ['context']
130
-
131
- if question_protocol == "":
132
- question_protocol = "Write questions based on the text"
133
- df['questions'] = df.apply(lambda row: get_questions(row['context'], question_protocol), axis=1)
134
-
135
- if answer_protocol == "":
136
- answer_protocol = "Write answers based on the text"
137
- df['answers'] = df.apply(lambda row: get_answers(row, answer_protocol), axis=1)
138
-
139
- df = df.drop('context', axis=1)
140
-
141
- csv = df.to_csv(index=False).encode('utf-8')
142
- st.download_button(
143
- label="Download Q/A pairs as CSV",
144
- data=csv,
145
- file_name='questions_answers.csv',
146
- mime='text/csv',
147
- )
148
- else:
149
- st.error("Please upload at least 1 PDF")
 
114
  submit = st.button("Submit")
115
 
116
  if submit:
117
+ client = OpenAI(api_key=openai_api_key)
118
+
119
+ try:
120
+ client.Model.list()
121
+ except:
122
+ st.error("OpenAI API key is invalid")
123
 
124
+ if uploaded_files:
125
+ textify_output = read_and_textify_advanced(uploaded_files, sentence_chunks)
126
+
127
+ df = pd.DataFrame(textify_output)
128
+ df.columns = ['context']
129
+
130
+ if question_protocol == "":
131
+ question_protocol = "Write questions based on the text"
132
+ df['questions'] = df.apply(lambda row: get_questions(row['context'], question_protocol), axis=1)
133
+
134
+ if answer_protocol == "":
135
+ answer_protocol = "Write answers based on the text"
136
+ df['answers'] = df.apply(lambda row: get_answers(row, answer_protocol), axis=1)
137
+
138
+ df = df.drop('context', axis=1)
139
+
140
+ csv = df.to_csv(index=False).encode('utf-8')
141
+ st.download_button(
142
+ label="Download Q/A pairs as CSV",
143
+ data=csv,
144
+ file_name='questions_answers.csv',
145
+ mime='text/csv',
146
+ )
147
+ else:
148
+ st.error("Please upload at least 1 PDF")