Update app.py
Browse files
app.py
CHANGED
@@ -84,10 +84,6 @@ def process_pasted_data(data):
|
|
84 |
reader = csv.reader(data_io, delimiter='\n', quotechar='"')
|
85 |
return [row[0] for row in reader]
|
86 |
|
87 |
-
def concatenate_dfs(dfs):
|
88 |
-
combined_df = pd.concat(dfs, ignore_index=True)
|
89 |
-
return combined_df.to_csv(index=False).encode('utf-8')
|
90 |
-
|
91 |
# Streamlit layout
|
92 |
st.sidebar.title("DataForSEO API Parameters")
|
93 |
api_login = st.sidebar.text_input("API Login", value="[email protected]")
|
@@ -165,29 +161,33 @@ if add_row:
|
|
165 |
if reset:
|
166 |
st.session_state.clear()
|
167 |
|
168 |
-
# Main app layout
|
169 |
row_count = st.session_state.get("row_count", 1)
|
170 |
-
|
|
|
|
|
171 |
|
172 |
for i in range(row_count):
|
173 |
-
|
|
|
|
|
174 |
with col1:
|
175 |
-
target_url_key = f"target_url_{i}"
|
176 |
target_url = st.text_input(f"Enter the target URL {i + 1}", key=target_url_key)
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
st.download_button(
|
185 |
label=f"Download data as CSV for URL {i + 1}",
|
186 |
data=csv,
|
187 |
file_name=f'backlinks_{i + 1}.csv',
|
188 |
mime='text/csv',
|
189 |
-
key=f"download_{i}" # Unique key for each download button
|
190 |
)
|
|
|
|
|
191 |
|
192 |
# Generate and reset button logic
|
193 |
generate_button = st.sidebar.button("Generate All")
|
@@ -215,29 +215,6 @@ if generate_button:
|
|
215 |
url_id, df = results.get()
|
216 |
st.session_state[f"df_{url_id}"] = df
|
217 |
|
218 |
-
# Check if there's at least one DataFrame available for combined download
|
219 |
-
if any(st.session_state.get(f"df_{i}") is not None for i in range(row_count)):
|
220 |
-
if st.sidebar.button("Download Combined CSV"):
|
221 |
-
combined_csv = concatenate_dfs([st.session_state.get(f"df_{i}") for i in range(row_count) if st.session_state.get(f"df_{i}") is not None])
|
222 |
-
st.sidebar.download_button(
|
223 |
-
label="Download Combined Data as CSV",
|
224 |
-
data=combined_csv,
|
225 |
-
file_name='combined_backlinks.csv',
|
226 |
-
mime='text/csv',
|
227 |
-
key="combined_download" # Unique key for the combined download button
|
228 |
-
)
|
229 |
-
|
230 |
-
# Combined CSV download logic - this should be outside of the for loop
|
231 |
-
if dfs:
|
232 |
-
combined_csv = concatenate_dfs(dfs)
|
233 |
-
if st.sidebar.button("Download Combined CSV", key="combined_download"):
|
234 |
-
st.sidebar.download_button(
|
235 |
-
label="Download Combined Data as CSV",
|
236 |
-
data=combined_csv,
|
237 |
-
file_name='combined_backlinks.csv',
|
238 |
-
mime='text/csv',
|
239 |
-
)
|
240 |
-
|
241 |
# Display and download logic for each row
|
242 |
for i in range(row_count):
|
243 |
df_key = f"df_{i}"
|
@@ -251,4 +228,4 @@ for i in range(row_count):
|
|
251 |
mime='text/csv',
|
252 |
)
|
253 |
elif df is None and generate_button:
|
254 |
-
st.error(f"Failed to generate CSV for URL {i + 1}: No data returned from the API or data processing error.")
|
|
|
84 |
reader = csv.reader(data_io, delimiter='\n', quotechar='"')
|
85 |
return [row[0] for row in reader]
|
86 |
|
|
|
|
|
|
|
|
|
87 |
# Streamlit layout
|
88 |
st.sidebar.title("DataForSEO API Parameters")
|
89 |
api_login = st.sidebar.text_input("API Login", value="[email protected]")
|
|
|
161 |
if reset:
|
162 |
st.session_state.clear()
|
163 |
|
164 |
+
# Main app layout
|
165 |
row_count = st.session_state.get("row_count", 1)
|
166 |
+
|
167 |
+
# Create two columns: one for the target URL inputs, and one for the download buttons
|
168 |
+
col1, col2 = st.beta_columns(2)
|
169 |
|
170 |
for i in range(row_count):
|
171 |
+
target_url_key = f"target_url_{i}"
|
172 |
+
|
173 |
+
# Input fields in the first column
|
174 |
with col1:
|
|
|
175 |
target_url = st.text_input(f"Enter the target URL {i + 1}", key=target_url_key)
|
176 |
|
177 |
+
# Display and download logic for each row in the second column
|
178 |
+
with col2:
|
179 |
+
df_key = f"df_{i}"
|
180 |
+
df = st.session_state.get(df_key)
|
181 |
+
if df is not None:
|
182 |
+
csv = convert_df_to_csv(df)
|
183 |
st.download_button(
|
184 |
label=f"Download data as CSV for URL {i + 1}",
|
185 |
data=csv,
|
186 |
file_name=f'backlinks_{i + 1}.csv',
|
187 |
mime='text/csv',
|
|
|
188 |
)
|
189 |
+
elif df is None and generate_button:
|
190 |
+
st.error(f"Failed to generate CSV for URL {i + 1}: No data returned from the API or data processing error.")
|
191 |
|
192 |
# Generate and reset button logic
|
193 |
generate_button = st.sidebar.button("Generate All")
|
|
|
215 |
url_id, df = results.get()
|
216 |
st.session_state[f"df_{url_id}"] = df
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
# Display and download logic for each row
|
219 |
for i in range(row_count):
|
220 |
df_key = f"df_{i}"
|
|
|
228 |
mime='text/csv',
|
229 |
)
|
230 |
elif df is None and generate_button:
|
231 |
+
st.error(f"Failed to generate CSV for URL {i + 1}: No data returned from the API or data processing error.")
|