File size: 1,412 Bytes
d170e1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

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