Spaces:
Sleeping
Sleeping
Commit
·
5aeea08
1
Parent(s):
80a626b
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ import openai
|
|
8 |
from sklearn.neighbors import NearestNeighbors
|
9 |
import os
|
10 |
import time
|
|
|
|
|
11 |
|
12 |
def download_pdf(url, output_path):
|
13 |
urllib.request.urlretrieve(url, output_path)
|
@@ -132,6 +134,9 @@ st.markdown(description)
|
|
132 |
|
133 |
openAI_key = st.sidebar.text_input('API Key', value='sk-')
|
134 |
|
|
|
|
|
|
|
135 |
add_row = st.sidebar.button("Add row")
|
136 |
row_count = st.session_state.get("row_count", 1)
|
137 |
|
@@ -139,13 +144,25 @@ if add_row:
|
|
139 |
row_count += 1
|
140 |
st.session_state.row_count = row_count
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
for i in range(row_count):
|
143 |
col1, col2, col3, col4 = st.columns(4)
|
144 |
|
145 |
with col1:
|
146 |
-
url = st.text_input(f'PDF URL {i+1}', key=f'url{i}')
|
147 |
with col2:
|
148 |
-
question = st.text_input(f'Question {i+1}', key=f'question{i}')
|
149 |
with col3:
|
150 |
# Initialize session state for answer if not already done
|
151 |
if f'session_answer{i}' not in st.session_state:
|
|
|
8 |
from sklearn.neighbors import NearestNeighbors
|
9 |
import os
|
10 |
import time
|
11 |
+
import csv
|
12 |
+
from io import StringIO
|
13 |
|
14 |
def download_pdf(url, output_path):
|
15 |
urllib.request.urlretrieve(url, output_path)
|
|
|
134 |
|
135 |
openAI_key = st.sidebar.text_input('API Key', value='sk-')
|
136 |
|
137 |
+
data_section = st.sidebar.text_area("Paste Data:")
|
138 |
+
paste_data = st.sidebar.button("Paste Data")
|
139 |
+
|
140 |
add_row = st.sidebar.button("Add row")
|
141 |
row_count = st.session_state.get("row_count", 1)
|
142 |
|
|
|
144 |
row_count += 1
|
145 |
st.session_state.row_count = row_count
|
146 |
|
147 |
+
if paste_data:
|
148 |
+
data = StringIO(data_section.strip())
|
149 |
+
reader = csv.reader(data, delimiter=',', quotechar='"')
|
150 |
+
urls_questions = [row for row in reader]
|
151 |
+
|
152 |
+
row_count = len(urls_questions)
|
153 |
+
st.session_state.row_count = row_count
|
154 |
+
|
155 |
+
for i, url_question in enumerate(urls_questions):
|
156 |
+
st.session_state[f"url{i}"] = url_question[0]
|
157 |
+
st.session_state[f"question{i}"] = url_question[1]
|
158 |
+
|
159 |
for i in range(row_count):
|
160 |
col1, col2, col3, col4 = st.columns(4)
|
161 |
|
162 |
with col1:
|
163 |
+
url = st.text_input(f'PDF URL {i+1}', key=f'url{i}', value=st.session_state.get(f'url{i}', ''))
|
164 |
with col2:
|
165 |
+
question = st.text_input(f'Question {i+1}', key=f'question{i}', value=st.session_state.get(f'question{i}', ''))
|
166 |
with col3:
|
167 |
# Initialize session state for answer if not already done
|
168 |
if f'session_answer{i}' not in st.session_state:
|