DataSpa / app.py
TanU21's picture
Upload 6 files
d170e1e verified
import streamlit as st
import requests
from fastapi import FastAPI
from main import app as fastapi_app
import uvicorn
import threading
FASTAPI_URL = "http://127.0.0.1:8000/preprocess_data/"
# Start FastAPI server in background thread
def run_fastapi():
uvicorn.run(fastapi_app, host="127.0.0.1", port=8000)
threading.Thread(target=run_fastapi, daemon=True).start()
st.title("πŸ“Š Data Preprocessing App")
uploaded_file = st.file_uploader("Upload CSV File", type=["csv"])
if uploaded_file is not None:
st.write("βœ… File uploaded successfully!")
if st.button("πŸš€ Process Data"):
if uploaded_file is None:
st.warning("⚠️ Please upload a CSV file first!")
else:
with st.spinner("Processing... ⏳"):
files = {"upload_file": (uploaded_file.name, uploaded_file, "text/csv")}
response = requests.post(FASTAPI_URL, files=files)
if response.status_code == 200:
st.success("βœ… Data processed successfully!")
cleaned_data_path = "cleaned_dataset.csv"
with open(cleaned_data_path, "wb") as f:
f.write(response.content)
with open(cleaned_data_path, "rb") as f:
st.download_button("πŸ“₯ Download Processed CSV", f, "cleaned_dataset.csv", "text/csv")
else:
st.error(f"❌ Error: {response.json()['detail']}")