DrishtiSharma commited on
Commit
3977b30
Β·
verified Β·
1 Parent(s): 85c7288

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -34
app.py CHANGED
@@ -25,7 +25,7 @@ from datasets import load_dataset
25
  import tempfile
26
 
27
  st.title("SQL-RAG Using CrewAI πŸš€")
28
- st.write("Analyze datasets using natural language queries")
29
 
30
  # Initialize LLM
31
  llm = None
@@ -169,15 +169,12 @@ def create_pdf_report_with_viz(report, conclusion, visualizations):
169
 
170
  return temp_pdf
171
 
172
-
173
  def escape_markdown(text):
174
- # Ensure the input is a string
175
- if not isinstance(text, str):
176
- text = str(text) if text is not None else ""
177
-
178
- # Escape special markdown characters
179
- escape_chars = r"\*`_{}[]()#+-.!"
180
- return re.sub(f'([{re.escape(escape_chars)}])', r'\\\1', text)
181
 
182
  # SQL-RAG Analysis
183
  if st.session_state.df is not None:
@@ -266,6 +263,8 @@ if st.session_state.df is not None:
266
  context=[analyze_data],
267
  )
268
 
 
 
269
  # Separate Crews for report and conclusion
270
  crew_report = Crew(
271
  agents=[sql_dev, data_analyst, report_writer],
@@ -327,29 +326,8 @@ if st.session_state.df is not None:
327
  # Step 6: Display Concise Conclusion
328
  #st.markdown("#### Conclusion")
329
 
330
- if conclusion_result:
331
- # Check if conclusion_result is a dictionary or list
332
- if isinstance(conclusion_result, dict):
333
- # Assuming the actual conclusion is inside a 'content' or similar key
334
- conclusion_text = conclusion_result.get('content', '')
335
- elif isinstance(conclusion_result, list):
336
- # If it's a list, join all items into a single string
337
- conclusion_text = " ".join(map(str, conclusion_result))
338
- else:
339
- conclusion_text = str(conclusion_result)
340
-
341
- # Remove any leading 'Conclusion:' in the result
342
- cleaned_conclusion = re.sub(r'^\s*\*\*?Conclusion:?(\*\*)?\s*', '', conclusion_text, flags=re.IGNORECASE)
343
-
344
- # Escape markdown characters
345
- safe_conclusion = escape_markdown(cleaned_conclusion)
346
-
347
- # Display the clean conclusion
348
- st.markdown(f"### Conclusion\n\n{safe_conclusion}")
349
- else:
350
- st.warning("⚠️ No Conclusion Generated.")
351
-
352
-
353
 
354
  # Full Data Visualization Tab
355
  with tab2:
@@ -378,5 +356,3 @@ else:
378
  with st.sidebar:
379
  st.header("πŸ“š Reference:")
380
  st.markdown("[SQL Agents w CrewAI & Llama 3 - Plaban Nayak](https://github.com/plaban1981/Agents/blob/main/SQL_Agents_with_CrewAI_and_Llama_3.ipynb)")
381
-
382
-
 
25
  import tempfile
26
 
27
  st.title("SQL-RAG Using CrewAI πŸš€")
28
+ st.write("Analyze datasets using natural language queries powered by SQL and CrewAI.")
29
 
30
  # Initialize LLM
31
  llm = None
 
169
 
170
  return temp_pdf
171
 
 
172
  def escape_markdown(text):
173
+ # Ensure text is a string
174
+ text = str(text)
175
+ # Escape Markdown characters: *, _, `, ~
176
+ escape_chars = r"(\*|_|`|~)"
177
+ return re.sub(escape_chars, r"\\\1", text)
 
 
178
 
179
  # SQL-RAG Analysis
180
  if st.session_state.df is not None:
 
263
  context=[analyze_data],
264
  )
265
 
266
+
267
+
268
  # Separate Crews for report and conclusion
269
  crew_report = Crew(
270
  agents=[sql_dev, data_analyst, report_writer],
 
326
  # Step 6: Display Concise Conclusion
327
  #st.markdown("#### Conclusion")
328
 
329
+ safe_conclusion = escape_markdown(conclusion_result if conclusion_result else "⚠️ No Conclusion Generated.")
330
+ st.markdown(safe_conclusion)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
 
332
  # Full Data Visualization Tab
333
  with tab2:
 
356
  with st.sidebar:
357
  st.header("πŸ“š Reference:")
358
  st.markdown("[SQL Agents w CrewAI & Llama 3 - Plaban Nayak](https://github.com/plaban1981/Agents/blob/main/SQL_Agents_with_CrewAI_and_Llama_3.ipynb)")