axel-darmouni commited on
Commit
9cb7c11
Β·
1 Parent(s): 2dd2794

update to code agent

Browse files
Files changed (2) hide show
  1. app.py +8 -8
  2. followup_agent.py +42 -30
app.py CHANGED
@@ -729,14 +729,14 @@ with gr.Blocks(title="πŸ€– French Public Data Analysis Agent", theme=gr.themes.S
729
  followup_section_header = gr.HTML("""
730
  <div style="text-align: center; margin: 2rem 0;">
731
  <h2 style="color: #374151; margin-bottom: 0.5rem;">πŸ€– Follow-up Analysis</h2>
732
- <p style="color: #6b7280; margin: 0;">Ask questions about the generated report and dataset</p>
733
  </div>
734
  """, visible=False)
735
 
736
  with gr.Row(visible=False) as followup_input_row:
737
  followup_input = gr.Textbox(
738
  label="Follow-up Question",
739
- placeholder="e.g., Show me correlation between two columns, Create a chart for specific regions, What are the trends over time?",
740
  scale=4
741
  )
742
  followup_button = gr.Button(
@@ -772,12 +772,12 @@ with gr.Blocks(title="πŸ€– French Public Data Analysis Agent", theme=gr.themes.S
772
 
773
  with gr.Row(visible=False) as followup_examples_row:
774
  followup_examples = [
775
- ("πŸ“Š Correlation Analysis", "Show me the correlation between two numerical columns with a scatter plot"),
776
- ("πŸ“ˆ Statistical Summary", "Create a comprehensive statistical summary with visualization for a specific column"),
777
- ("🎯 Filter & Analyze", "Filter the data by specific criteria and create a visualization"),
778
- ("πŸ“‹ Dataset Overview", "Give me a detailed summary of the dataset structure and contents"),
779
- ("πŸ“‰ Trend Analysis", "Create a line chart showing trends over time for specific data"),
780
- ("πŸ” Custom Visualization", "Create a custom bar/pie/histogram chart for specific columns"),
781
  ]
782
 
783
  for emoji_text, query_text in followup_examples:
 
729
  followup_section_header = gr.HTML("""
730
  <div style="text-align: center; margin: 2rem 0;">
731
  <h2 style="color: #374151; margin-bottom: 0.5rem;">πŸ€– Follow-up Analysis</h2>
732
+ <p style="color: #6b7280; margin: 0;">Ask about report findings, request data analysis, or get contextual information</p>
733
  </div>
734
  """, visible=False)
735
 
736
  with gr.Row(visible=False) as followup_input_row:
737
  followup_input = gr.Textbox(
738
  label="Follow-up Question",
739
+ placeholder="e.g., What are the main findings?, Show me correlation between columns, What is road safety policy in France?",
740
  scale=4
741
  )
742
  followup_button = gr.Button(
 
772
 
773
  with gr.Row(visible=False) as followup_examples_row:
774
  followup_examples = [
775
+ ("πŸ“‹ Report Summary", "What were the main findings from the analysis?"),
776
+ ("🌐 Context Info", "What is the policy context for this data in France?"),
777
+ ("πŸ“Š Create Chart", "Show me the correlation between two numerical columns with a scatter plot"),
778
+ ("πŸ“ˆ Data Statistics", "Give me statistical summary for a specific column"),
779
+ ("🎯 Filter Data", "Filter the data by specific criteria and show results"),
780
+ ("πŸ” General Question", "Tell me more about this topic and its importance"),
781
  ]
782
 
783
  for emoji_text, query_text in followup_examples:
followup_agent.py CHANGED
@@ -57,37 +57,49 @@ def generate_followup_prompt(user_question, report_context=None):
57
 
58
  USER'S FOLLOW-UP QUESTION: "{user_question}"
59
 
 
 
 
 
 
 
 
 
 
60
  AVAILABLE TOOLS:
61
- 1. **load_previous_dataset()** - Load the dataset used in the previous analysis
62
- 2. **get_dataset_summary(df)** - Get detailed info about the dataset structure
63
- 3. **get_previous_report_content()** - Get context about the previous report
64
- 4. **create_followup_visualization()** - Create new charts and graphs (bar, line, scatter, histogram, box, pie)
65
- 5. **analyze_column_correlation()** - Analyze relationships between columns with scatter plots
66
- 6. **create_statistical_summary()** - Generate comprehensive stats + visualizations for any column
67
- 7. **filter_and_visualize_data()** - Filter data by criteria and create targeted visualizations
68
- 8. **search_datasets()** - Search for additional datasets if needed
69
- 9. **get_dataset_info()** - Get info about specific datasets
70
-
71
- ANALYSIS APPROACH:
72
- 1. First, get context by calling get_previous_report_content()
73
- 2. Load the previous dataset using load_previous_dataset()
74
- 3. Get a summary of the dataset structure with get_dataset_summary()
75
- 4. Based on the user's question, perform the appropriate analysis:
76
- - Create new visualizations if they want different charts
77
- - Analyze correlations if they ask about relationships
78
- - Filter or group data if they want specific subsets
79
- - Calculate statistics if they want numerical insights
80
- 5. **ALWAYS create visualizations when relevant** - save to generated_data folder
81
- 6. Provide a comprehensive text answer AND create supporting visualizations
82
-
83
- IMPORTANT GUIDELINES:
84
- - Always start by understanding the previous report context
85
- - Use the same dataset that was used in the original analysis
86
- - **CREATE VISUALIZATIONS whenever possible** - charts help answer questions better
87
- - Provide clear, actionable insights in TEXT format
88
- - Save all new visualization files to the generated_data folder with descriptive filenames
89
- - Be concise but thorough in your explanations
90
- - Combine text analysis with visual evidence
 
 
 
91
 
92
  Answer the user's question: "{user_question}"
93
  """
 
57
 
58
  USER'S FOLLOW-UP QUESTION: "{user_question}"
59
 
60
+ IMPORTANT: Analyze the user's question carefully to determine what type of response is needed.
61
+
62
+ QUESTION ANALYSIS:
63
+ - **General Information/Web Search**: If the question asks for general information, definitions, or requires web search (e.g., "What is X?", "Tell me about Y", "How does Z work?"), use web search tools and provide a text answer. DO NOT load datasets or create visualizations.
64
+
65
+ - **Dataset Questions**: If the question is specifically about the dataset, data analysis, statistics, or requests visualizations (e.g., "Show me correlation", "Create a chart", "What's the distribution of X?", "Filter by Y"), then use dataset tools.
66
+
67
+ - **Report Context**: If the question asks about the previous report content or findings, use get_previous_report_content() and provide a text answer.
68
+
69
  AVAILABLE TOOLS:
70
+ 1. **DuckDuckGoSearchTool** - For general web search and information queries
71
+ 2. **get_previous_report_content()** - Get context about the previous report
72
+ 3. **load_previous_dataset()** - Load the dataset (ONLY if question needs data analysis)
73
+ 4. **get_dataset_summary(df)** - Get dataset structure info
74
+ 5. **create_followup_visualization()** - Create charts (ONLY if explicitly requested)
75
+ 6. **analyze_column_correlation()** - Analyze column relationships with plots
76
+ 7. **create_statistical_summary()** - Generate stats with visualizations
77
+ 8. **filter_and_visualize_data()** - Filter data and create targeted visualizations
78
+ 9. **search_datasets()** - Search for additional datasets
79
+ 10. **get_dataset_info()** - Get info about specific datasets
80
+
81
+ RESPONSE STRATEGY:
82
+ 1. **First, determine the question type:**
83
+ - Is this a general knowledge/web search question? β†’ Use web search, provide text answer
84
+ - Is this about the previous report content? β†’ Use get_previous_report_content(), provide text answer
85
+ - Is this a data analysis question? β†’ Use dataset tools as needed
86
+ - Does it explicitly ask for a chart/visualization? β†’ Use appropriate visualization tools
87
+
88
+ 2. **For data analysis questions only:**
89
+ - Load dataset if you need to analyze the actual data
90
+ - Create visualizations ONLY if the user explicitly asks for them or if the question specifically requires visual analysis (correlations, distributions, trends)
91
+ - Provide clear text explanations
92
+
93
+ 3. **Be efficient with tool usage:**
94
+ - Use the minimum number of tools needed to answer the question
95
+ - Don't create visualizations unless requested or clearly needed
96
+ - Don't load datasets for general questions
97
+
98
+ GUIDELINES:
99
+ - Match your response type to the question type
100
+ - Be direct and efficient - don't over-engineer the response
101
+ - Only use data analysis tools when the question is actually about data analysis
102
+ - Provide concise, helpful answers focused on what the user asked
103
 
104
  Answer the user's question: "{user_question}"
105
  """