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