joshuadunlop commited on
Commit
6e8b587
·
1 Parent(s): e1c5134

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -26
app.py CHANGED
@@ -129,29 +129,37 @@ description = """ PDF GPT allows you to chat with your PDF file using Universal
129
 
130
  st.markdown(description)
131
 
132
- openAI_key = st.sidebar.text_input('Enter your OpenAI API key here')
133
-
134
- col1, col2, col3, col4 = st.columns(4)
135
-
136
- with col1:
137
- url = st.text_input('PDF URL')
138
- with col2:
139
- question = st.text_input('Question')
140
- with col3:
141
- answer_placeholder = st.empty()
142
- answer_placeholder.text_area('Answer', value='')
143
- with col4:
144
- if st.button('Submit'):
145
- if openAI_key.strip()=='':
146
- st.error('Please enter you Open AI Key')
147
- elif url.strip() == '':
148
- st.error('URL field is empty')
149
- elif question.strip() == '':
150
- st.error('Question field is empty')
151
- else:
152
- glob_url = url
153
- download_pdf(glob_url, 'corpus.pdf')
154
- load_recommender('corpus.pdf')
155
-
156
- answer = generate_answer(question,openAI_key)
157
- answer_placeholder.text_area('Answer', value=answer)
 
 
 
 
 
 
 
 
 
129
 
130
  st.markdown(description)
131
 
132
+ openAI_key = st.sidebar.text_input('API Key', value='sk-')
133
+
134
+ add_row = st.sidebar.button("Add row")
135
+ row_count = st.session_state.get("row_count", 1)
136
+
137
+ if add_row:
138
+ row_count += 1
139
+ st.session_state.row_count = row_count
140
+
141
+ for i in range(row_count):
142
+ col1, col2, col3, col4 = st.columns(4)
143
+
144
+ with col1:
145
+ url = st.text_input(f'PDF URL {i+1}', key=f'url{i}')
146
+ with col2:
147
+ question = st.text_input(f'Question {i+1}', key=f'question{i}')
148
+ with col3:
149
+ answer_placeholder = st.empty()
150
+ answer_placeholder.text_area(f'Answer {i+1}', key=f'answer{i}', value='')
151
+ with col4:
152
+ if st.button(f'Submit {i+1}'):
153
+ if openAI_key.strip()=='':
154
+ st.error('Please enter you Open AI Key')
155
+ elif url.strip() == '':
156
+ st.error('URL field is empty')
157
+ elif question.strip() == '':
158
+ st.error('Question field is empty')
159
+ else:
160
+ glob_url = url
161
+ download_pdf(glob_url, 'corpus.pdf')
162
+ load_recommender('corpus.pdf')
163
+
164
+ answer = generate_answer(question,openAI_key)
165
+ answer_placeholder.text_area(f'Answer {i+1}', key=f'answer{i}', value=answer)