Spaces:
Running
Running
Commit
·
c8cc09f
1
Parent(s):
0b49979
progress more 37+
Browse files
app.py
CHANGED
@@ -174,11 +174,8 @@ def process_file(uploaded_file):
|
|
174 |
return processed_df
|
175 |
|
176 |
def create_output_file(df, uploaded_file, analysis_df):
|
177 |
-
#
|
178 |
-
wb =
|
179 |
-
|
180 |
-
# Remove the default sheet created by openpyxl
|
181 |
-
wb.remove(wb.active)
|
182 |
|
183 |
# Process data for 'Сводка' sheet
|
184 |
entities = df['Объект'].unique()
|
@@ -198,9 +195,10 @@ def create_output_file(df, uploaded_file, analysis_df):
|
|
198 |
summary_df = summary_df.sort_values('Отрицательные', ascending=False)
|
199 |
|
200 |
# Write 'Сводка' sheet
|
201 |
-
ws = wb
|
202 |
-
for
|
203 |
-
|
|
|
204 |
|
205 |
# Process data for 'Значимые' sheet
|
206 |
significant_data = []
|
@@ -210,26 +208,31 @@ def create_output_file(df, uploaded_file, analysis_df):
|
|
210 |
significant_data.append([row['Объект'], sentiment, row['Заголовок'], row['Выдержки из текста']])
|
211 |
|
212 |
# Write 'Значимые' sheet
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
|
218 |
# Write 'Анализ' sheet
|
219 |
-
ws = wb
|
220 |
-
for
|
221 |
-
|
|
|
222 |
|
223 |
# Copy 'Публикации' sheet from original uploaded file
|
224 |
original_df = pd.read_excel(uploaded_file, sheet_name='Публикации')
|
225 |
-
ws = wb
|
226 |
-
for
|
227 |
-
|
|
|
228 |
|
229 |
# Add 'Тех.приложение' sheet with processed data
|
230 |
-
|
231 |
-
|
232 |
-
|
|
|
|
|
|
|
233 |
|
234 |
# Save the workbook to a BytesIO object
|
235 |
output = io.BytesIO()
|
@@ -239,7 +242,7 @@ def create_output_file(df, uploaded_file, analysis_df):
|
|
239 |
return output
|
240 |
|
241 |
def main():
|
242 |
-
st.title("... приступим к анализу... версия
|
243 |
|
244 |
uploaded_file = st.file_uploader("Выбирайте Excel-файл", type="xlsx")
|
245 |
|
|
|
174 |
return processed_df
|
175 |
|
176 |
def create_output_file(df, uploaded_file, analysis_df):
|
177 |
+
# Load the sample file to use as a template
|
178 |
+
wb = load_workbook("sample_file.xlsx")
|
|
|
|
|
|
|
179 |
|
180 |
# Process data for 'Сводка' sheet
|
181 |
entities = df['Объект'].unique()
|
|
|
195 |
summary_df = summary_df.sort_values('Отрицательные', ascending=False)
|
196 |
|
197 |
# Write 'Сводка' sheet
|
198 |
+
ws = wb['Сводка']
|
199 |
+
for r_idx, row in enumerate(dataframe_to_rows(summary_df, index=False, header=False), start=4):
|
200 |
+
for c_idx, value in enumerate(row, start=5):
|
201 |
+
ws.cell(row=r_idx, column=c_idx, value=value)
|
202 |
|
203 |
# Process data for 'Значимые' sheet
|
204 |
significant_data = []
|
|
|
208 |
significant_data.append([row['Объект'], sentiment, row['Заголовок'], row['Выдержки из текста']])
|
209 |
|
210 |
# Write 'Значимые' sheet
|
211 |
+
ws = wb['Значимые']
|
212 |
+
for r_idx, row in enumerate(significant_data, start=3):
|
213 |
+
for c_idx, value in enumerate(row, start=3):
|
214 |
+
ws.cell(row=r_idx, column=c_idx, value=value)
|
215 |
|
216 |
# Write 'Анализ' sheet
|
217 |
+
ws = wb['Анализ']
|
218 |
+
for r_idx, row in enumerate(dataframe_to_rows(analysis_df, index=False, header=False), start=4):
|
219 |
+
for c_idx, value in enumerate(row, start=5):
|
220 |
+
ws.cell(row=r_idx, column=c_idx, value=value)
|
221 |
|
222 |
# Copy 'Публикации' sheet from original uploaded file
|
223 |
original_df = pd.read_excel(uploaded_file, sheet_name='Публикации')
|
224 |
+
ws = wb['Публикации']
|
225 |
+
for r_idx, row in enumerate(dataframe_to_rows(original_df, index=False, header=True), start=1):
|
226 |
+
for c_idx, value in enumerate(row, start=1):
|
227 |
+
ws.cell(row=r_idx, column=c_idx, value=value)
|
228 |
|
229 |
# Add 'Тех.приложение' sheet with processed data
|
230 |
+
if 'Тех.приложение' not in wb.sheetnames:
|
231 |
+
wb.create_sheet('Тех.приложение')
|
232 |
+
ws = wb['Тех.приложение']
|
233 |
+
for r_idx, row in enumerate(dataframe_to_rows(df, index=False, header=True), start=1):
|
234 |
+
for c_idx, value in enumerate(row, start=1):
|
235 |
+
ws.cell(row=r_idx, column=c_idx, value=value)
|
236 |
|
237 |
# Save the workbook to a BytesIO object
|
238 |
output = io.BytesIO()
|
|
|
242 |
return output
|
243 |
|
244 |
def main():
|
245 |
+
st.title("... приступим к анализу... версия 37+")
|
246 |
|
247 |
uploaded_file = st.file_uploader("Выбирайте Excel-файл", type="xlsx")
|
248 |
|