Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- .gitattributes +1 -0
- app.py +184 -0
- chatbot.jpg +3 -0
- requirements.txt +9 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
chatbot.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,184 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit.components.v1 as components
|
3 |
+
import streamlit as st
|
4 |
+
from ydata_profiling import ProfileReport
|
5 |
+
from streamlit_pandas_profiling import st_profile_report
|
6 |
+
from langchain.llms.openai import OpenAI
|
7 |
+
from langchain_experimental.agents import create_csv_agent
|
8 |
+
from langchain.agents.agent_types import AgentType
|
9 |
+
import time
|
10 |
+
import os
|
11 |
+
from mitosheet.streamlit.v1 import spreadsheet
|
12 |
+
from pygwalker.api.streamlit import init_streamlit_comm, get_streamlit_html
|
13 |
+
|
14 |
+
# Global variable to store uploaded file
|
15 |
+
uploaded_file = None
|
16 |
+
|
17 |
+
def main():
|
18 |
+
global uploaded_file
|
19 |
+
st.sidebar.title("App Options")
|
20 |
+
option = st.sidebar.selectbox("Choose an option", ["View Instructions", "View Data","Data Profiling","Tableau AI", "CSV Chatbot"])
|
21 |
+
|
22 |
+
if option == "View Instructions":
|
23 |
+
show_instructions()
|
24 |
+
elif option == "Data Profiling":
|
25 |
+
data_profiling()
|
26 |
+
elif option == "CSV Chatbot":
|
27 |
+
csv_chatbot()
|
28 |
+
elif option == "View Data":
|
29 |
+
view_data()
|
30 |
+
elif option == "Tableau AI":
|
31 |
+
tableau_ai()
|
32 |
+
|
33 |
+
def show_instructions():
|
34 |
+
st.title("Welcome to the AI TOOL - Made for MDH")
|
35 |
+
st.write("This tool offers several functionalities to help you analyze and work with your data.")
|
36 |
+
st.write("Please select an option from the sidebar to proceed:")
|
37 |
+
st.write("- **View Data:** Upload a CSV file and view its contents.")
|
38 |
+
st.write("- **Data Profiling:** Upload a CSV file to generate a data profiling report.")
|
39 |
+
st.write("- **CSV Chatbot:** Interact with a chatbot to get insights from your CSV data.")
|
40 |
+
st.write("- **Tableau AI:** Upload a CSV file to visualize it using Tableau AI.")
|
41 |
+
st.write("- **View Instructions:** View these instructions again.")
|
42 |
+
|
43 |
+
def data_profiling():
|
44 |
+
global uploaded_file
|
45 |
+
st.title("Data Profiling App")
|
46 |
+
if uploaded_file is None:
|
47 |
+
uploaded_file = st.file_uploader("Upload CSV file", type=["csv", "xlsx"])
|
48 |
+
if uploaded_file is None:
|
49 |
+
st.warning("Please upload a CSV or Excel file.")
|
50 |
+
st.stop() # Stop execution if no file uploaded
|
51 |
+
|
52 |
+
if uploaded_file.name.endswith('.xlsx'):
|
53 |
+
# Load Excel file into pandas DataFrame
|
54 |
+
df_excel = pd.read_excel(uploaded_file)
|
55 |
+
# Save DataFrame as CSV
|
56 |
+
csv_filename = uploaded_file.name.replace('.xlsx', '.csv')
|
57 |
+
df_excel.to_csv(csv_filename, index=False)
|
58 |
+
st.success(f"Excel file converted to CSV: {csv_filename}")
|
59 |
+
# Set uploaded file to the converted CSV file
|
60 |
+
uploaded_file = open(csv_filename, 'rb')
|
61 |
+
|
62 |
+
df = pd.read_csv(uploaded_file)
|
63 |
+
st.dataframe(df)
|
64 |
+
|
65 |
+
# Generate and display the data profile report
|
66 |
+
pr = ProfileReport(df, title="Report")
|
67 |
+
st_profile_report(pr)
|
68 |
+
|
69 |
+
def csv_chatbot():
|
70 |
+
global uploaded_file
|
71 |
+
st.sidebar.title("OpenAI Settings")
|
72 |
+
st.title("Personal Assistant")
|
73 |
+
st.text("A BR CREATION")
|
74 |
+
st.warning("Also try Google PALM @ [PALMCSV](https://palmcsvbot.streamlit.app/)")
|
75 |
+
st.image("chatbot.jpg", caption="Chatbot", width=178)
|
76 |
+
|
77 |
+
if uploaded_file is None:
|
78 |
+
uploaded_file = st.file_uploader("Upload CSV file", type=["csv", "xlsx"])
|
79 |
+
if uploaded_file is None:
|
80 |
+
st.warning("Please upload a CSV or Excel file.")
|
81 |
+
st.stop() # Stop execution if no file uploaded
|
82 |
+
|
83 |
+
openai_api_key = st.text_input("Enter your OpenAI API Key", type="password")
|
84 |
+
if not openai_api_key:
|
85 |
+
st.warning("You should have an OpenAI API key to continue. Get one at [OpenAI API Keys](https://platform.openai.com/api-keys)")
|
86 |
+
st.stop()
|
87 |
+
|
88 |
+
os.environ['OPENAI_API_KEY'] = openai_api_key
|
89 |
+
llm = OpenAI(temperature=0)
|
90 |
+
agent = create_csv_agent(
|
91 |
+
llm,
|
92 |
+
uploaded_file,
|
93 |
+
verbose=False,
|
94 |
+
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
95 |
+
)
|
96 |
+
|
97 |
+
predefined_questions = ["How many rows are there in the dataset?", "Explain the dataset."]
|
98 |
+
selected_question = st.selectbox("Select a question", ["Select a question"] + predefined_questions)
|
99 |
+
custom_question = st.text_input("Or ask a custom question")
|
100 |
+
|
101 |
+
if st.button("Ask"):
|
102 |
+
if selected_question != "Select a question":
|
103 |
+
query = selected_question
|
104 |
+
elif custom_question.strip() != "":
|
105 |
+
query = custom_question.strip()
|
106 |
+
else:
|
107 |
+
st.warning("Please select a predefined question or ask a custom question.")
|
108 |
+
return
|
109 |
+
|
110 |
+
start = time.time()
|
111 |
+
answer = agent.run(query)
|
112 |
+
end = time.time()
|
113 |
+
st.write(answer)
|
114 |
+
st.write(f"Answer (took {round(end - start, 2)} s.)")
|
115 |
+
|
116 |
+
def view_data():
|
117 |
+
global uploaded_file
|
118 |
+
st.title("Data Viewer Portal")
|
119 |
+
if uploaded_file is None:
|
120 |
+
uploaded_file = st.file_uploader("Upload CSV file", type=["csv", "xlsx"])
|
121 |
+
if uploaded_file is None:
|
122 |
+
st.warning("Please upload a CSV or Excel file.")
|
123 |
+
st.stop() # Stop execution if no file uploaded
|
124 |
+
|
125 |
+
if uploaded_file.name.endswith('.xlsx'):
|
126 |
+
# Load Excel file into pandas DataFrame
|
127 |
+
df_excel = pd.read_excel(uploaded_file)
|
128 |
+
# Save DataFrame as CSV
|
129 |
+
csv_filename = uploaded_file.name.replace('.xlsx', '.csv')
|
130 |
+
df_excel.to_csv(csv_filename, index=False)
|
131 |
+
st.success(f"Excel file converted to CSV: {csv_filename}")
|
132 |
+
# Set uploaded file to the converted CSV file
|
133 |
+
uploaded_file = open(csv_filename, 'rb')
|
134 |
+
|
135 |
+
df = pd.read_csv(uploaded_file)
|
136 |
+
|
137 |
+
# Convert the dataframe to a list of dictionaries
|
138 |
+
dataframe = df.to_dict(orient="records")
|
139 |
+
|
140 |
+
# Display the dataframe in a Mito spreadsheet
|
141 |
+
final_dfs, code = spreadsheet(dataframe)
|
142 |
+
|
143 |
+
def tableau_ai():
|
144 |
+
global uploaded_file
|
145 |
+
st.title("Virtual Tableau AI Tool")
|
146 |
+
init_streamlit_comm()
|
147 |
+
|
148 |
+
# Function to get PygWalker HTML
|
149 |
+
@st.cache_data
|
150 |
+
def get_pyg_html(df: pd.DataFrame) -> str:
|
151 |
+
html = get_streamlit_html(df, use_kernel_calc=True, debug=False)
|
152 |
+
return html
|
153 |
+
|
154 |
+
# Function to get user uploaded DataFrame
|
155 |
+
def get_user_uploaded_data():
|
156 |
+
if uploaded_file is not None:
|
157 |
+
return pd.read_csv(uploaded_file)
|
158 |
+
return None
|
159 |
+
|
160 |
+
if uploaded_file is None:
|
161 |
+
uploaded_file = st.file_uploader("Upload a CSV file", type=["csv", "xlsx"])
|
162 |
+
if uploaded_file is None:
|
163 |
+
st.warning("Please upload a CSV or Excel file.")
|
164 |
+
st.stop() # Stop execution if no file uploaded
|
165 |
+
|
166 |
+
if uploaded_file.name.endswith('.xlsx'):
|
167 |
+
# Load Excel file into pandas DataFrame
|
168 |
+
df_excel = pd.read_excel(uploaded_file)
|
169 |
+
# Save DataFrame as CSV
|
170 |
+
csv_filename = uploaded_file.name.replace('.xlsx', '.csv')
|
171 |
+
df_excel.to_csv(csv_filename, index=False)
|
172 |
+
st.success(f"Excel file converted to CSV: {csv_filename}")
|
173 |
+
# Set uploaded file to the converted CSV file
|
174 |
+
uploaded_file = open(csv_filename, 'rb')
|
175 |
+
|
176 |
+
df = get_user_uploaded_data()
|
177 |
+
|
178 |
+
if df is not None:
|
179 |
+
components.html(get_pyg_html(df), width=1300, height=1000, scrolling=True)
|
180 |
+
else:
|
181 |
+
st.write("Please upload a CSV file to proceed.")
|
182 |
+
|
183 |
+
if __name__ == "__main__":
|
184 |
+
main()
|
chatbot.jpg
ADDED
![]() |
Git LFS Details
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain
|
2 |
+
langchain_experimental
|
3 |
+
openai
|
4 |
+
streamlit
|
5 |
+
tabulate
|
6 |
+
ydata_profiling
|
7 |
+
mitosheet
|
8 |
+
streamlit-pandas-profiling
|
9 |
+
pygwalker
|