DrishtiSharma commited on
Commit
cbd7b69
Β·
verified Β·
1 Parent(s): dd622b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -3
app.py CHANGED
@@ -87,17 +87,17 @@ if st.session_state.df is not None:
87
 
88
  @tool("tables_schema")
89
  def tables_schema(tables: str) -> str:
90
- """Get schema and sample rows for given tables."""
91
  return InfoSQLDatabaseTool(db=db).invoke(tables)
92
 
93
  @tool("execute_sql")
94
  def execute_sql(sql_query: str) -> str:
95
- """Execute a SQL query against the database."""
96
  return QuerySQLDataBaseTool(db=db).invoke(sql_query)
97
 
98
  @tool("check_sql")
99
  def check_sql(sql_query: str) -> str:
100
- """Check the validity of a SQL query."""
101
  return QuerySQLCheckerTool(db=db, llm=llm).invoke({"query": sql_query})
102
 
103
  sql_dev = Agent(
@@ -149,3 +149,34 @@ if st.session_state.df is not None:
149
  verbose=True,
150
  )
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  @tool("tables_schema")
89
  def tables_schema(tables: str) -> str:
90
+ """Get the schema and sample rows for the specified tables."""
91
  return InfoSQLDatabaseTool(db=db).invoke(tables)
92
 
93
  @tool("execute_sql")
94
  def execute_sql(sql_query: str) -> str:
95
+ """Execute a SQL query against the database and return the results."""
96
  return QuerySQLDataBaseTool(db=db).invoke(sql_query)
97
 
98
  @tool("check_sql")
99
  def check_sql(sql_query: str) -> str:
100
+ """Validate the SQL query syntax and structure before execution."""
101
  return QuerySQLCheckerTool(db=db, llm=llm).invoke({"query": sql_query})
102
 
103
  sql_dev = Agent(
 
149
  verbose=True,
150
  )
151
 
152
+ # UI: Tabs for Query Results and General Insights
153
+ tab1, tab2 = st.tabs(["πŸ” Query Insights + Viz", "πŸ“Š Full Data Viz"])
154
+
155
+ with tab1:
156
+ query = st.text_area("Enter Query:", placeholder="e.g., 'What is the average salary for senior employees?'")
157
+ if st.button("Submit Query"):
158
+ with st.spinner("Processing query..."):
159
+ inputs = {"query": query}
160
+ result = crew.kickoff(inputs=inputs)
161
+ st.markdown("### Analysis Report:")
162
+ st.markdown(result)
163
+
164
+ # Query-Specific Visualization
165
+ if "salary" in query.lower():
166
+ fig = px.box(st.session_state.df, x="job_title", y="salary_in_usd", title="Salary Distribution by Job Title")
167
+ st.plotly_chart(fig)
168
+
169
+ with tab2:
170
+ st.subheader("πŸ“Š Comprehensive Data Visualizations")
171
+
172
+ fig1 = px.histogram(st.session_state.df, x="job_title", title="Job Title Frequency")
173
+ st.plotly_chart(fig1)
174
+
175
+ fig2 = px.bar(st.session_state.df.groupby("experience_level")["salary_in_usd"].mean().reset_index(),
176
+ x="experience_level", y="salary_in_usd", title="Average Salary by Experience Level")
177
+ st.plotly_chart(fig2)
178
+
179
+ temp_dir.cleanup()
180
+ else:
181
+ st.info("Please load a dataset to proceed.")
182
+