Update app.py
Browse files
app.py
CHANGED
@@ -172,34 +172,12 @@ row_count = st.session_state.get("row_count", 1)
|
|
172 |
# Define placeholders for each row in the second column
|
173 |
download_placeholders = [st.empty() for _ in range(row_count)]
|
174 |
|
175 |
-
for i in
|
176 |
-
col1, _ = st.columns(2)
|
177 |
target_url_key = f"target_url_{i}"
|
178 |
|
179 |
-
with
|
180 |
st.text_input(f"Enter the target URL {i + 1}", key=target_url_key)
|
181 |
|
182 |
-
with col2:
|
183 |
-
# Use placeholders for download buttons
|
184 |
-
download_placeholder = st.empty()
|
185 |
-
|
186 |
-
# Conditionally display download buttons or error messages
|
187 |
-
if 'generate_pressed' in st.session_state:
|
188 |
-
df_key = f"df_{i}"
|
189 |
-
df = st.session_state.get(df_key)
|
190 |
-
|
191 |
-
if df is not None:
|
192 |
-
csv = convert_df_to_csv(df)
|
193 |
-
download_placeholder.download_button(
|
194 |
-
label=f"Download data as CSV for URL {i + 1}",
|
195 |
-
data=csv,
|
196 |
-
file_name=f'backlinks_{i + 1}.csv',
|
197 |
-
mime='text/csv',
|
198 |
-
)
|
199 |
-
else:
|
200 |
-
# This will only show an error if the generation process has been initiated
|
201 |
-
download_placeholder.error(f"Failed to generate CSV for URL {i + 1}: No data returned from the API or data processing error.")
|
202 |
-
|
203 |
if 'generate_pressed' in st.session_state and st.session_state['generate_pressed']:
|
204 |
jobs = Queue()
|
205 |
results = Queue()
|
@@ -223,21 +201,22 @@ if 'generate_pressed' in st.session_state and st.session_state['generate_pressed
|
|
223 |
url_id, df = results.get()
|
224 |
st.session_state[f"df_{url_id}"] = df
|
225 |
|
226 |
-
# Update placeholders
|
227 |
-
for i,
|
228 |
df_key = f"df_{i}"
|
229 |
df = st.session_state.get(df_key)
|
230 |
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
|
|
241 |
|
242 |
# Display and download logic for each row
|
243 |
for i in range(row_count):
|
|
|
172 |
# Define placeholders for each row in the second column
|
173 |
download_placeholders = [st.empty() for _ in range(row_count)]
|
174 |
|
175 |
+
for i, (col1_placeholder, col2_placeholder) in enumerate(placeholders):
|
|
|
176 |
target_url_key = f"target_url_{i}"
|
177 |
|
178 |
+
with col1_placeholder.container():
|
179 |
st.text_input(f"Enter the target URL {i + 1}", key=target_url_key)
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
if 'generate_pressed' in st.session_state and st.session_state['generate_pressed']:
|
182 |
jobs = Queue()
|
183 |
results = Queue()
|
|
|
201 |
url_id, df = results.get()
|
202 |
st.session_state[f"df_{url_id}"] = df
|
203 |
|
204 |
+
# Update placeholders in the second column
|
205 |
+
for i, (_, col2_placeholder) in enumerate(placeholders):
|
206 |
df_key = f"df_{i}"
|
207 |
df = st.session_state.get(df_key)
|
208 |
|
209 |
+
with col2_placeholder.container():
|
210 |
+
if df is not None:
|
211 |
+
csv = convert_df_to_csv(df)
|
212 |
+
st.download_button(
|
213 |
+
label=f"Download data as CSV for URL {i + 1}",
|
214 |
+
data=csv,
|
215 |
+
file_name=f'backlinks_{i + 1}.csv',
|
216 |
+
mime='text/csv',
|
217 |
+
)
|
218 |
+
else:
|
219 |
+
st.error(f"Failed to generate CSV for URL {i + 1}: No data returned from the API or data processing error.")
|
220 |
|
221 |
# Display and download logic for each row
|
222 |
for i in range(row_count):
|