Spaces:
Sleeping
Sleeping
Commit
·
e5251a6
1
Parent(s):
5f18847
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,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)
|
@@ -190,3 +193,24 @@ for i in range(row_count):
|
|
190 |
with col3:
|
191 |
answer_placeholder = st.empty()
|
192 |
answer_placeholder.text_area(f'Answer {i+1}', key=f'answer{i}', value=st.session_state[f'session_answer{i}'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
import time
|
11 |
import csv
|
12 |
from io import StringIO
|
13 |
+
import pandas as pd
|
14 |
+
from io import BytesIO
|
15 |
+
import base64
|
16 |
|
17 |
def download_pdf(url, output_path):
|
18 |
urllib.request.urlretrieve(url, output_path)
|
|
|
193 |
with col3:
|
194 |
answer_placeholder = st.empty()
|
195 |
answer_placeholder.text_area(f'Answer {i+1}', key=f'answer{i}', value=st.session_state[f'session_answer{i}'])
|
196 |
+
|
197 |
+
# Create a list of lists containing all URLs, questions, and answers
|
198 |
+
data = [[st.session_state.get(f'url{i}', ''), st.session_state.get(f'question{i}', ''), st.session_state.get(f'session_answer{i}', '')] for i in range(row_count)]
|
199 |
+
|
200 |
+
# Convert the data to a Pandas DataFrame
|
201 |
+
df = pd.DataFrame(data, columns=['URL', 'Question', 'Answer'])
|
202 |
+
|
203 |
+
# Generate a download link for the DataFrame
|
204 |
+
st.markdown(get_table_download_link(df), unsafe_allow_html=True)
|
205 |
+
|
206 |
+
def to_csv(data):
|
207 |
+
output = BytesIO()
|
208 |
+
writer = csv.writer(output)
|
209 |
+
writer.writerows(data)
|
210 |
+
return output.getvalue().decode('utf-8')
|
211 |
+
|
212 |
+
def get_table_download_link(df, filename="data.csv", text="Download CSV file"):
|
213 |
+
csv = df.to_csv(index=False)
|
214 |
+
b64 = base64.b64encode(csv.encode()).decode() # some strings <-> bytes conversions necessary here
|
215 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="{filename}">{text}</a>'
|
216 |
+
return href
|