Mustehson commited on
Commit
277bf9b
Β·
1 Parent(s): 031d4e1

Update Prompt

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +13 -15
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: πŸ“Š
4
  colorFrom: yellow
5
  colorTo: purple
6
  sdk: gradio
7
- sdk_version: 5.0.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: yellow
5
  colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 4.42.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py CHANGED
@@ -58,16 +58,16 @@ def get_table_schema(table):
58
  return ddl_create, full_path
59
 
60
 
61
- def get_visualization(question, tool):
62
  agent = ReactCodeAgent(tools=[tool], llm_engine=llm_engine, add_base_tools=True,
63
  additional_authorized_imports=['matplotlib.pyplot',
64
  'pandas', 'plotly.express',
65
  'seaborn'], max_iterations=10)
66
  fig = agent.run(
67
 
68
- task=f'''
69
-
70
- You are an expert in writing Visualization code. Here are the steps you should follow while writing code for Visualization:
71
  1. Select the most appropriate chart type for data. Use bar charts for categorical comparisons, line charts for trends over time, scatter plots for relationships between variables, pie charts for proportions, histograms for distribution analysis, and box plots for visualizing data spread and outliers.
72
  2. Ensure clear and appropriate labels, colors, and design elements, keeping visual elements legible and uncluttered.
73
  3. Follow best practices, avoiding unnecessary visual distractions (chartjunk).
@@ -77,13 +77,12 @@ def get_visualization(question, tool):
77
  7. Ensure that categorical data is plotted on one axis and numerical data on the other, with appropriate labels that clearly represent the data being visualized.
78
  8. When plotting categorical data, arrange categories in a meaningful order (e.g., by size, time, or frequency) rather than randomly.
79
  9. Ensure that the categorical data are plotted on the x-axis, and the frequencies (numerical data) are plotted on the y-axis.
80
- 10. Do not write functions.
81
- 11. Use seaborn.
82
- 12. In the end you have to return a dict which contain final fig as fig key, Generated SQL as sql key, Data as a dataframe with data key using the `final_answer` tool.
83
- DO NOT PRINT THE FINAL ANSWER OR FINAL OUTPUT
84
- Here is the task:
85
- task: {question}
86
- ''',
87
  )
88
 
89
  return fig
@@ -110,13 +109,12 @@ def main(table, text_query):
110
  fig, ax = plt.subplots()
111
  ax.set_axis_off()
112
 
113
- schema, _ = get_table_schema(table)
114
- tool.description = f"""Allows you to perform SQL queries on the table. Returns a pandas dataframe representation of the result.
115
- The table schema is as follows: \n{schema}"""
116
 
117
 
118
  try:
119
- output = get_visualization(question=text_query, tool=tool)
120
  fig = output.get('fig', None)
121
  generated_sql = output.get('sql', None)
122
  data = output.get('data', None)
 
58
  return ddl_create, full_path
59
 
60
 
61
+ def get_visualization(question, tool, schema, table_name):
62
  agent = ReactCodeAgent(tools=[tool], llm_engine=llm_engine, add_base_tools=True,
63
  additional_authorized_imports=['matplotlib.pyplot',
64
  'pandas', 'plotly.express',
65
  'seaborn'], max_iterations=10)
66
  fig = agent.run(
67
 
68
+ instruction='''
69
+ THINK STEP BY STEP
70
+ Here are the steps you should follow while writing code for Visualization:
71
  1. Select the most appropriate chart type for data. Use bar charts for categorical comparisons, line charts for trends over time, scatter plots for relationships between variables, pie charts for proportions, histograms for distribution analysis, and box plots for visualizing data spread and outliers.
72
  2. Ensure clear and appropriate labels, colors, and design elements, keeping visual elements legible and uncluttered.
73
  3. Follow best practices, avoiding unnecessary visual distractions (chartjunk).
 
77
  7. Ensure that categorical data is plotted on one axis and numerical data on the other, with appropriate labels that clearly represent the data being visualized.
78
  8. When plotting categorical data, arrange categories in a meaningful order (e.g., by size, time, or frequency) rather than randomly.
79
  9. Ensure that the categorical data are plotted on the x-axis, and the frequencies (numerical data) are plotted on the y-axis.
80
+ 10. Use seaborn
81
+ 11. In the end you have to return a dict which contain final fig as fig key, Generated SQL as sql key, Data as a dataframe with data key using the `final_answer` tool e.g. final_answer(answer={"fig": fig, "sql": sql, "data": data})''',
82
+
83
+ task= f'{question}',
84
+ schema= f'{schema}',
85
+ table_name= f'{table_name}',
 
86
  )
87
 
88
  return fig
 
109
  fig, ax = plt.subplots()
110
  ax.set_axis_off()
111
 
112
+ schema, table_name = get_table_schema(table)
113
+ tool.description = f"""Allows you to perform SQL queries on the table. Returns a pandas dataframe representation of the result."""
 
114
 
115
 
116
  try:
117
+ output = get_visualization(question=text_query, tool=tool, schema=schema, table_name=table_name)
118
  fig = output.get('fig', None)
119
  generated_sql = output.get('sql', None)
120
  data = output.get('data', None)