Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import pandas as pd | |
| from fpdf import FPDF | |
| def excel_to_pdf(file): | |
| # Load Excel file | |
| df = pd.read_excel(file.name) | |
| # Create PDF object | |
| pdf = FPDF() | |
| pdf.add_page() | |
| # Add table headers | |
| pdf.set_font("Arial", size=12) | |
| col_width = pdf.w / (len(df.columns) + 1) | |
| row_height = pdf.font_size | |
| for col in df.columns: | |
| pdf.cell(col_width, row_height, col, border=1) | |
| pdf.ln(row_height) | |
| # Add table rows | |
| for row in df.itertuples(index=False): | |
| for item in row: | |
| pdf.cell(col_width, row_height, str(item), border=1) | |
| pdf.ln(row_height) | |
| # Save PDF to a file | |
| output_pdf = "output.pdf" | |
| pdf.output(output_pdf) | |
| return output_pdf | |
| # Gradio Interface | |
| iface = gr.Interface( | |
| fn=excel_to_pdf, | |
| inputs=gr.File(label="Upload Excel File", type="filepath"), | |
| outputs=gr.File(label="Download PDF File") | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |