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']}")