AILab-123 / app.py
SuriRaja's picture
Update app.py
09b3c0a verified
raw
history blame contribute delete
939 Bytes
import gradio as gr
import pandas as pd
import xport.v56
import tempfile
import os
def convert_xpt_to_csv(xpt_file):
try:
# Save uploaded file to a temp file
with tempfile.NamedTemporaryFile(delete=False, suffix=".xpt") as temp:
temp.write(xpt_file.read())
xpt_path = temp.name
# Load using xport v56 parser
with open(xpt_path, "rb") as f:
lib = xport.v56.load(f)
df = pd.DataFrame(lib)
# Save as CSV
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()