aiscientist commited on
Commit
5ce8557
1 Parent(s): 28719ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -38
app.py CHANGED
@@ -11,33 +11,22 @@ import os
11
  from mitosheet.streamlit.v1 import spreadsheet
12
  from pygwalker.api.streamlit import init_streamlit_comm, get_streamlit_html
13
 
14
- st.set_page_config(
15
- page_title="AI TOOL",
16
- layout="wide"
17
- )
18
 
19
  def main():
 
20
  st.sidebar.title("App Options")
21
  option = st.sidebar.selectbox("Choose an option", ["View Instructions", "View Data","Data Profiling","Tableau AI", "CSV Chatbot"])
22
 
23
  if option == "View Instructions":
24
  show_instructions()
25
  elif option == "Data Profiling":
26
- uploaded_file = st.file_uploader("Upload CSV file", type=["csv"])
27
- if uploaded_file is None:
28
- st.warning("Please upload a CSV file.")
29
- st.stop() # Stop execution if no file uploaded
30
- else:
31
- data_profiling(uploaded_file)
32
  elif option == "CSV Chatbot":
33
- openai_api_key = st.text_input("Enter your OpenAI API Key", type="password")
34
- if not openai_api_key:
35
- st.warning("You should have an OpenAI API key to continue. Get one at [OpenAI API Keys](https://platform.openai.com/api-keys)")
36
- st.stop()
37
- os.environ['OPENAI_API_KEY'] = openai_api_key
38
- personal_assistant()
39
  elif option == "View Data":
40
- virtual_excel_sheet()
41
  elif option == "Tableau AI":
42
  tableau_ai()
43
 
@@ -50,36 +39,52 @@ def show_instructions():
50
  st.write("- **CSV Chatbot:** Interact with a chatbot to get insights from your CSV data.")
51
  st.write("- **Tableau AI:** Upload a CSV file to visualize it using Tableau AI.")
52
  st.write("- **View Instructions:** View these instructions again.")
53
- st.markdown(
54
- """
55
- <a href="https://www.linkedin.com/in/your_linkedin_profile/" target="_blank">
56
- <img src="https://github.com/dheereshagrwal/colored-icons/blob/master/public/icons/linkedin/linkedin.svg" width="30" height="30"/>
57
- </a>
58
- <a href="https://github.com/your_github_username" target="_blank">
59
- <img src="https://img.icons8.com/fluency/48/000000/github.png" width="30" height="30"/>
60
- </a>
61
- """,
62
- unsafe_allow_html=True
63
- )
64
- def data_profiling(uploaded_file):
65
  st.title("Data Profiling App")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  df = pd.read_csv(uploaded_file)
67
  st.dataframe(df)
 
68
  # Generate and display the data profile report
69
  pr = ProfileReport(df, title="Report")
70
  st_profile_report(pr)
71
 
72
- def personal_assistant():
 
73
  st.sidebar.title("OpenAI Settings")
74
  st.title("Personal Assistant")
75
  st.text("A BR CREATION")
76
  st.image("chatbot.jpg", caption="Chatbot", width=178)
77
 
78
- uploaded_file = st.file_uploader("Upload CSV file", type=["csv"])
79
  if uploaded_file is None:
80
- st.warning("Please upload a CSV file.")
81
- st.stop() # Stop execution if no file uploaded
 
 
 
 
 
 
 
82
 
 
83
  llm = OpenAI(temperature=0)
84
  agent = create_csv_agent(
85
  llm,
@@ -107,12 +112,24 @@ def personal_assistant():
107
  st.write(answer)
108
  st.write(f"Answer (took {round(end - start, 2)} s.)")
109
 
110
- def virtual_excel_sheet():
 
111
  st.title("Data Viewer Portal")
112
- uploaded_file = st.file_uploader("Upload CSV file", type=["csv"])
113
  if uploaded_file is None:
114
- st.warning("Please upload a CSV file.")
115
- st.stop() # Stop execution if no file uploaded
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  df = pd.read_csv(uploaded_file)
118
 
@@ -123,6 +140,7 @@ def virtual_excel_sheet():
123
  final_dfs, code = spreadsheet(dataframe)
124
 
125
  def tableau_ai():
 
126
  st.title("Virtual Tableau AI Tool")
127
  init_streamlit_comm()
128
 
@@ -134,11 +152,26 @@ def tableau_ai():
134
 
135
  # Function to get user uploaded DataFrame
136
  def get_user_uploaded_data():
137
- uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
138
  if uploaded_file is not None:
139
  return pd.read_csv(uploaded_file)
140
  return None
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  df = get_user_uploaded_data()
143
 
144
  if df is not None:
 
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
 
 
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.image("chatbot.jpg", caption="Chatbot", width=178)
75
 
 
76
  if uploaded_file is None:
77
+ uploaded_file = st.file_uploader("Upload CSV file", type=["csv", "xlsx"])
78
+ if uploaded_file is None:
79
+ st.warning("Please upload a CSV or Excel file.")
80
+ st.stop() # Stop execution if no file uploaded
81
+
82
+ openai_api_key = st.text_input("Enter your OpenAI API Key", type="password")
83
+ if not openai_api_key:
84
+ st.warning("You should have an OpenAI API key to continue. Get one at [OpenAI API Keys](https://platform.openai.com/api-keys)")
85
+ st.stop()
86
 
87
+ os.environ['OPENAI_API_KEY'] = openai_api_key
88
  llm = OpenAI(temperature=0)
89
  agent = create_csv_agent(
90
  llm,
 
112
  st.write(answer)
113
  st.write(f"Answer (took {round(end - start, 2)} s.)")
114
 
115
+ def view_data():
116
+ global uploaded_file
117
  st.title("Data Viewer Portal")
 
118
  if uploaded_file is None:
119
+ uploaded_file = st.file_uploader("Upload CSV file", type=["csv", "xlsx"])
120
+ if uploaded_file is None:
121
+ st.warning("Please upload a CSV or Excel file.")
122
+ st.stop() # Stop execution if no file uploaded
123
+
124
+ if uploaded_file.name.endswith('.xlsx'):
125
+ # Load Excel file into pandas DataFrame
126
+ df_excel = pd.read_excel(uploaded_file)
127
+ # Save DataFrame as CSV
128
+ csv_filename = uploaded_file.name.replace('.xlsx', '.csv')
129
+ df_excel.to_csv(csv_filename, index=False)
130
+ st.success(f"Excel file converted to CSV: {csv_filename}")
131
+ # Set uploaded file to the converted CSV file
132
+ uploaded_file = open(csv_filename, 'rb')
133
 
134
  df = pd.read_csv(uploaded_file)
135
 
 
140
  final_dfs, code = spreadsheet(dataframe)
141
 
142
  def tableau_ai():
143
+ global uploaded_file
144
  st.title("Virtual Tableau AI Tool")
145
  init_streamlit_comm()
146
 
 
152
 
153
  # Function to get user uploaded DataFrame
154
  def get_user_uploaded_data():
 
155
  if uploaded_file is not None:
156
  return pd.read_csv(uploaded_file)
157
  return None
158
 
159
+ if uploaded_file is None:
160
+ uploaded_file = st.file_uploader("Upload a CSV file", type=["csv", "xlsx"])
161
+ if uploaded_file is None:
162
+ st.warning("Please upload a CSV or Excel file.")
163
+ st.stop() # Stop execution if no file uploaded
164
+
165
+ if uploaded_file.name.endswith('.xlsx'):
166
+ # Load Excel file into pandas DataFrame
167
+ df_excel = pd.read_excel(uploaded_file)
168
+ # Save DataFrame as CSV
169
+ csv_filename = uploaded_file.name.replace('.xlsx', '.csv')
170
+ df_excel.to_csv(csv_filename, index=False)
171
+ st.success(f"Excel file converted to CSV: {csv_filename}")
172
+ # Set uploaded file to the converted CSV file
173
+ uploaded_file = open(csv_filename, 'rb')
174
+
175
  df = get_user_uploaded_data()
176
 
177
  if df is not None: