Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import pandas as pd
|
|
| 3 |
from fuzzywuzzy import process, fuzz
|
| 4 |
import tempfile
|
| 5 |
import os
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def auto_correct_names(series, threshold=90):
|
| 8 |
"""Auto-correct typos in chatter names using fuzzy matching."""
|
|
@@ -21,6 +23,23 @@ def auto_correct_names(series, threshold=90):
|
|
| 21 |
|
| 22 |
return series.replace(name_mapping)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def process_file(input_file):
|
| 25 |
"""Process uploaded Excel file and return output"""
|
| 26 |
try:
|
|
@@ -61,6 +80,10 @@ def process_file(input_file):
|
|
| 61 |
# Create temp file for output
|
| 62 |
temp_file_path = os.path.join(tempfile.gettempdir(), "processed_schedule.xlsx")
|
| 63 |
final_df.to_excel(temp_file_path, index=False, sheet_name='Schedule')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
return final_df, temp_file_path
|
| 65 |
|
| 66 |
except Exception as e:
|
|
@@ -104,4 +127,3 @@ with gr.Blocks(title="Schedule Processor") as demo:
|
|
| 104 |
if __name__ == "__main__":
|
| 105 |
demo.launch()
|
| 106 |
|
| 107 |
-
|
|
|
|
| 3 |
from fuzzywuzzy import process, fuzz
|
| 4 |
import tempfile
|
| 5 |
import os
|
| 6 |
+
from openpyxl import load_workbook
|
| 7 |
+
from openpyxl.styles import Alignment
|
| 8 |
|
| 9 |
def auto_correct_names(series, threshold=90):
|
| 10 |
"""Auto-correct typos in chatter names using fuzzy matching."""
|
|
|
|
| 23 |
|
| 24 |
return series.replace(name_mapping)
|
| 25 |
|
| 26 |
+
def adjust_excel_formatting(file_path):
|
| 27 |
+
"""Adjust column widths and enable text wrapping in Excel file."""
|
| 28 |
+
wb = load_workbook(file_path)
|
| 29 |
+
ws = wb.active
|
| 30 |
+
|
| 31 |
+
# Adjust column widths and enable text wrapping
|
| 32 |
+
for col in ws.columns:
|
| 33 |
+
max_length = 0
|
| 34 |
+
col_letter = col[0].column_letter
|
| 35 |
+
for cell in col:
|
| 36 |
+
if cell.value:
|
| 37 |
+
max_length = max(max_length, len(str(cell.value)))
|
| 38 |
+
cell.alignment = Alignment(wrap_text=True) # Enable text wrapping
|
| 39 |
+
ws.column_dimensions[col_letter].width = max_length + 2 # Adjust column width
|
| 40 |
+
|
| 41 |
+
wb.save(file_path)
|
| 42 |
+
|
| 43 |
def process_file(input_file):
|
| 44 |
"""Process uploaded Excel file and return output"""
|
| 45 |
try:
|
|
|
|
| 80 |
# Create temp file for output
|
| 81 |
temp_file_path = os.path.join(tempfile.gettempdir(), "processed_schedule.xlsx")
|
| 82 |
final_df.to_excel(temp_file_path, index=False, sheet_name='Schedule')
|
| 83 |
+
|
| 84 |
+
# Adjust formatting to ensure everything fits within cells
|
| 85 |
+
adjust_excel_formatting(temp_file_path)
|
| 86 |
+
|
| 87 |
return final_df, temp_file_path
|
| 88 |
|
| 89 |
except Exception as e:
|
|
|
|
| 127 |
if __name__ == "__main__":
|
| 128 |
demo.launch()
|
| 129 |
|
|
|