Spaces:
Runtime error
Runtime error
Mustehson
commited on
Commit
Β·
c74f0d5
1
Parent(s):
98c19b6
Data, SQL, Fig
Browse files
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: π
|
|
4 |
colorFrom: yellow
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: mit
|
|
|
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
|
app.py
CHANGED
@@ -66,8 +66,9 @@ def get_visualization(question, tool):
|
|
66 |
fig = agent.run(
|
67 |
|
68 |
task=f'''
|
|
|
69 |
Here are the steps you should follow while writing code for Visualization:
|
70 |
-
1. Select the most
|
71 |
2. Ensure clear and appropriate labels, colors, and design elements, keeping visual elements legible and uncluttered.
|
72 |
3. Follow best practices, avoiding unnecessary visual distractions (chartjunk).
|
73 |
4. Ensure the code is error-free, with correct fields, transformations, and aesthetics.
|
@@ -77,8 +78,7 @@ def get_visualization(question, tool):
|
|
77 |
8. When plotting categorical data, arrange categories in a meaningful order (e.g., by size, time, or frequency) rather than randomly.
|
78 |
9. Ensure that the categorical data are plotted on the x-axis, and the frequencies (numerical data) are plotted on the y-axis.
|
79 |
10. Use seaborn
|
80 |
-
11. In the end you have to return a final fig using the `final_answer` tool.
|
81 |
-
|
82 |
Here is the task:
|
83 |
task: {question}
|
84 |
''',
|
@@ -114,12 +114,16 @@ def main(table, text_query):
|
|
114 |
|
115 |
|
116 |
try:
|
117 |
-
|
|
|
|
|
|
|
118 |
except Exception as e:
|
119 |
gr.Warning(f"β Unable to generate the visualization. {e}")
|
120 |
|
121 |
|
122 |
-
return fig
|
|
|
123 |
|
124 |
|
125 |
custom_css = """
|
@@ -141,7 +145,7 @@ custom_css = """
|
|
141 |
"""
|
142 |
|
143 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="indigo"), css=custom_css) as demo:
|
144 |
-
gr.Image("logo.png", label=None, show_label=False, container=False, height=100)
|
145 |
|
146 |
gr.Markdown("""
|
147 |
<div style='text-align: center;'>
|
@@ -168,9 +172,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="indigo"
|
|
168 |
with gr.Tabs():
|
169 |
with gr.Tab("Plot"):
|
170 |
result_plot = gr.Plot()
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
schema_dropdown.change(update_tables, inputs=schema_dropdown, outputs=tables_dropdown)
|
173 |
-
generate_query_button.click(main, inputs=[tables_dropdown, query_input], outputs=[result_plot])
|
174 |
|
175 |
if __name__ == "__main__":
|
176 |
demo.launch(debug=True)
|
|
|
66 |
fig = agent.run(
|
67 |
|
68 |
task=f'''
|
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).
|
74 |
4. Ensure the code is error-free, with correct fields, transformations, and aesthetics.
|
|
|
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.
|
|
|
82 |
Here is the task:
|
83 |
task: {question}
|
84 |
''',
|
|
|
114 |
|
115 |
|
116 |
try:
|
117 |
+
output = get_visualization(question=text_query, tool=tool)
|
118 |
+
fig = output.get('fig', None)
|
119 |
+
generated_sql = output.get('sql', None)
|
120 |
+
data = output.get('data', None)
|
121 |
except Exception as e:
|
122 |
gr.Warning(f"β Unable to generate the visualization. {e}")
|
123 |
|
124 |
|
125 |
+
return fig, generated_sql, data
|
126 |
+
|
127 |
|
128 |
|
129 |
custom_css = """
|
|
|
145 |
"""
|
146 |
|
147 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="indigo"), css=custom_css) as demo:
|
148 |
+
# gr.Image("logo.png", label=None, show_label=False, container=False, height=100)
|
149 |
|
150 |
gr.Markdown("""
|
151 |
<div style='text-align: center;'>
|
|
|
172 |
with gr.Tabs():
|
173 |
with gr.Tab("Plot"):
|
174 |
result_plot = gr.Plot()
|
175 |
+
with gr.Tab("SQL"):
|
176 |
+
generated_sql = gr.Textbox(lines=TAB_LINES, label="Generated SQL", value="", interactive=False,
|
177 |
+
autoscroll=False)
|
178 |
+
with gr.Tab("Data"):
|
179 |
+
data = gr.Dataframe(label="Data", interactive=False)
|
180 |
|
181 |
schema_dropdown.change(update_tables, inputs=schema_dropdown, outputs=tables_dropdown)
|
182 |
+
generate_query_button.click(main, inputs=[tables_dropdown, query_input], outputs=[result_plot, generated_sql, data])
|
183 |
|
184 |
if __name__ == "__main__":
|
185 |
demo.launch(debug=True)
|