Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,37 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import os
|
| 4 |
-
from csv_agent import generate_code
|
| 5 |
-
|
| 6 |
-
st.set_page_config(page_title="CSV Assistant with Hugging Face", layout="wide")
|
| 7 |
-
st.title("🤖 CSV Assistant: Powered by FLAN-T5-Large")
|
| 8 |
-
|
| 9 |
-
# Check API token
|
| 10 |
-
if os.getenv("HUGGINGFACEHUB_API_TOKEN") is None:
|
| 11 |
-
st.error("❌ API Token missing! Please set HUGGINGFACEHUB_API_TOKEN in your Space Secrets.")
|
| 12 |
-
st.stop()
|
| 13 |
-
|
| 14 |
-
st.sidebar.title("Upload Your CSV")
|
| 15 |
-
uploaded_file = st.sidebar.file_uploader("Choose a CSV file", type=["csv"])
|
| 16 |
-
|
| 17 |
-
if uploaded_file:
|
| 18 |
-
df = pd.read_csv(uploaded_file)
|
| 19 |
-
st.write("### Preview of your data:", df.head())
|
| 20 |
-
|
| 21 |
-
prompt = st.text_input("💬 What would you like to do with the data?")
|
| 22 |
-
if prompt:
|
| 23 |
-
with st.spinner("Generating Python code using AI..."):
|
| 24 |
-
code = generate_code(prompt)
|
| 25 |
-
st.code(code, language="python")
|
| 26 |
-
|
| 27 |
-
try:
|
| 28 |
-
exec_globals = {"df": df}
|
| 29 |
-
exec(code, exec_globals)
|
| 30 |
-
df = exec_globals["df"]
|
| 31 |
-
st.success("✅ Data updated successfully!")
|
| 32 |
-
st.write(df.head())
|
| 33 |
-
|
| 34 |
-
csv = df.to_csv(index=False).encode('utf-8')
|
| 35 |
-
st.download_button("⬇️ Download Updated CSV", csv, "updated_data.csv", "text/csv")
|
| 36 |
-
except Exception as e:
|
| 37 |
-
st.error(f"⚠️ Error while executing AI-generated code: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|