Download app.py from TanU21/DataSpa: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/spaces/TanU21/DataSpa/resolve/main/app.py
- Command line
-
hf download hf://spaces/TanU21/DataSpa/app.py
-
curl -L -o app.py https://huggingface.co/spaces/TanU21/DataSpa/resolve/main/app.py
1.41 kB
| 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']}") | |