| import gradio as gr |
| import pandas as pd |
| import xport.v56 |
| import tempfile |
| import os |
|
|
| def convert_xpt_to_csv(xpt_file): |
| try: |
| |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".xpt") as temp: |
| temp.write(xpt_file.read()) |
| xpt_path = temp.name |
|
|
| |
| with open(xpt_path, "rb") as f: |
| lib = xport.v56.load(f) |
| df = pd.DataFrame(lib) |
|
|
| |
| csv_path = xpt_path.replace(".xpt", ".csv") |
| df.to_csv(csv_path, index=False) |
| return csv_path |
|
|
| except Exception as e: |
| return f"❌ Error: {str(e)}" |
|
|
| gr.Interface( |
| fn=convert_xpt_to_csv, |
| inputs=gr.File(label="Upload .XPT File"), |
| outputs=gr.File(label="Download .CSV File"), |
| title="XPT to CSV Converter", |
| description="Upload SAS XPORT (.xpt) files and get CSV output instantly." |
| ).launch() |
|
|