Skip to content

Commit

Permalink
plotly images
Browse files Browse the repository at this point in the history
  • Loading branch information
zainhoda committed Jul 28, 2023
1 parent 9091ec8 commit 7e0460b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2,839 deletions.
2,869 changes: 32 additions & 2,837 deletions notebooks/vn-ask.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"requests", "tabulate", "plotly", "pandas"
"requests", "tabulate", "plotly", "kaleido", "pandas"
]

[project.urls]
Expand Down
9 changes: 8 additions & 1 deletion src/vanna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,14 +982,21 @@ def ask(question: Union[str, None] = None, print_results: bool = True, auto_trai
plotly_code = generate_plotly_code(question=question, sql=sql, df=df)
fig = get_plotly_figure(plotly_code=plotly_code, df=df)
if print_results:
fig.show()
try:
display = __import__('IPython.display', fromlist=['display']).display
Image = __import__('IPython.display', fromlist=['Image']).Image
img_bytes = fig.to_image(format="png", scale=2)
display(Image(img_bytes))
except Exception as e:
fig.show()

if generate_followups:
followup_questions = generate_followup_questions(question=question, df=df)
if print_results and followup_questions is not None and len(followup_questions) > 0:
print("AI-generated follow-up questions:")
for followup_question in followup_questions:
print(followup_question)
pass

if print_results:
return None
Expand Down

0 comments on commit 7e0460b

Please sign in to comment.