Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,6 +72,7 @@ def display_file(input_files):
|
|
| 72 |
|
| 73 |
|
| 74 |
|
|
|
|
| 75 |
def show_intermediate_outputs(show_intermediate):
|
| 76 |
if show_intermediate:
|
| 77 |
return gr.Accordion.update(visible=True)
|
|
@@ -202,6 +203,32 @@ def flag_if_shared(flag_method):
|
|
| 202 |
return flag_method(request, *args, **kwargs)
|
| 203 |
return proxy
|
| 204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
def process_and_output_files(input_files):
|
| 206 |
data = []
|
| 207 |
|
|
@@ -268,7 +295,7 @@ def process_and_output_files(input_files):
|
|
| 268 |
df = pd.DataFrame(string_data)
|
| 269 |
|
| 270 |
filename = "output.xlsx"
|
| 271 |
-
|
| 272 |
|
| 273 |
table_html = df.to_html(classes="table table-bordered", index=True)
|
| 274 |
scrollable_table = f'<div style="overflow-x: auto;">{table_html}</div>'
|
|
@@ -279,6 +306,8 @@ def process_and_output_files(input_files):
|
|
| 279 |
|
| 280 |
|
| 281 |
|
|
|
|
|
|
|
| 282 |
with gr.Blocks(title="Automatic Reimbursement Tool Demo") as page:
|
| 283 |
gr.Markdown("<center><h1>Automatic Reimbursement Tool Demo</h1></center>")
|
| 284 |
gr.Markdown("<h2>Description</h2>")
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
+
|
| 76 |
def show_intermediate_outputs(show_intermediate):
|
| 77 |
if show_intermediate:
|
| 78 |
return gr.Accordion.update(visible=True)
|
|
|
|
| 203 |
return flag_method(request, *args, **kwargs)
|
| 204 |
return proxy
|
| 205 |
|
| 206 |
+
def save_df_to_excel_with_autowidth(df, filename):
|
| 207 |
+
# Save DataFrame to Excel without any formatting
|
| 208 |
+
df.to_excel(filename, index=False, engine='openpyxl')
|
| 209 |
+
|
| 210 |
+
# Open the Excel file with openpyxl to adjust column widths
|
| 211 |
+
book = load_workbook(filename)
|
| 212 |
+
sheet = book.active
|
| 213 |
+
|
| 214 |
+
# Loop through columns and adjust the width based on max length in each column
|
| 215 |
+
for column in sheet.columns:
|
| 216 |
+
max_length = 0
|
| 217 |
+
column = [cell for cell in column]
|
| 218 |
+
for cell in column:
|
| 219 |
+
try:
|
| 220 |
+
if len(str(cell.value)) > max_length:
|
| 221 |
+
max_length = len(cell.value)
|
| 222 |
+
except:
|
| 223 |
+
pass
|
| 224 |
+
adjusted_width = (max_length + 2) # adding a little extra space
|
| 225 |
+
sheet.column_dimensions[get_column_letter(column[0].column)].width = adjusted_width
|
| 226 |
+
|
| 227 |
+
# Save the changes back to the Excel file
|
| 228 |
+
book.save(filename)
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
|
| 232 |
def process_and_output_files(input_files):
|
| 233 |
data = []
|
| 234 |
|
|
|
|
| 295 |
df = pd.DataFrame(string_data)
|
| 296 |
|
| 297 |
filename = "output.xlsx"
|
| 298 |
+
save_df_to_excel_with_autowidth(df, filename)
|
| 299 |
|
| 300 |
table_html = df.to_html(classes="table table-bordered", index=True)
|
| 301 |
scrollable_table = f'<div style="overflow-x: auto;">{table_html}</div>'
|
|
|
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
+
|
| 310 |
+
|
| 311 |
with gr.Blocks(title="Automatic Reimbursement Tool Demo") as page:
|
| 312 |
gr.Markdown("<center><h1>Automatic Reimbursement Tool Demo</h1></center>")
|
| 313 |
gr.Markdown("<h2>Description</h2>")
|