pandas-ai
pandas-ai copied to clipboard
support save charts to a specified path
🚀 The feature
support save charts to a specified path.
instead of
project_root = dirname(dirname(dirname(__file__)))
chart_save_dir = os.path.join(project_root, f"exports\\charts\\{date}")
Motivation, pitch
users want to get the result picture, but you just print the path.
Alternatives
No response
Additional context
No response
The issue is due to the file separator because on windows, the separator is a backslash \
, while on Unix-based systems it is a forward slash /
.
I also noticed this yesterday where it created a dir like this (on mac):
(testenv) MacBook-Pro:pandas-ai$ ls
CONTRIBUTING.md README.md exports\charts\2023-06-02 pandasai setup.py
LICENSE dist images poetry.lock testenv
MANIFEST.in docs mkdocs.yml poetry.toml tests
Notebooks examples pai pyproject.toml
I will add a quick fix asap
@sandiemann I suppose it's still not working.
I think we should also change the behavior here:
ast.parse(f"plt.savefig(r'{chart_save_dir}\\{filename}.png')")
@gventuri Yeah, as you can see
Answer: Charts saved to: C:\ProgramData\anaconda3\lib\site-packages\exports\charts\2023-06-05
What i mean is that 1.You only return the directory of the pic , not the path of the pic. 2.I can not specify the path for the pic.
You should use
new_body.append(ast.parse(f"print(r'Charts saved to: {chart_save_dir}')"))
@wqh17101 What if multiple charts are created? Should the path for each be printed?
@gventuri added the additional fix for the save chart dir. P.S. the old PR is closed.
Good Questions. @jonbiemond Maybe you can use a task id to manage this. ETC: Every call will generate a task_id. task_id=str(uuid.uuid4()) And make a directory named by task_id instead of date. Then return the file list in the task_id dir.
Agree that saving to a specific folder for each run, or let the user specify where the charts should be saved is important. This would make it easier to use pandasai inside of something like a fastapi, where the correct chart files can easily be sent through the API and allow for multiple api calls from different users at the same time.
Okay, unless I misunderstand there are two separate requests here:
- @wqh17101 Display the exact file path of the saved charts for the user.
- @mitokic Save charts to a unique folder per prompt.
@wqh17101 Do you mind updating the title of your issue? As it's written it seems as though your asking to be able to pass your own path to PandasAI where charts should be saved.
Note: PRs #214 and #229 are not related to either of these requests. I suggest they be unlinked.
@jonbiemond
it's written it seems as though your asking to be able to pass your own path to PandasAI where charts should be saved.
This is what i need too.
Okay, unless I misunderstand there are two separate requests here:
1. @wqh17101 Display the exact file path of the saved charts for the user. 2. @mitokic Save charts to a unique folder per prompt.
@wqh17101 Do you mind updating the title of your issue? As it's written it seems as though your asking to be able to pass your own path to PandasAI where charts should be saved.
Note: PRs #214 and #229 are not related to either of these requests. I suggest they be unlinked.
@jonbiemond yes, the PRs are addressing the issue to fix saving charts correctly on the export dir i.e. on unix system. should I open another issue and link these PRs to be more specific about fixing the path.
on the @wqh17101 request, we could extend the current save chart functionality to take additional param for desired export dir where we can specify the path.
@sandiemann Yes, I think that's a good idea to create a separate issue about the file path problems on Unix.
I personally don't like the idea of adding another parameter, because I think it clutters the interface. Alternatively we could accept a file path as a variable to the existing parameter. (does feel overloaded)
-
pandas_ai = PandasAI(llm, save_charts='user/specified/path')
Or perhaps set save chart parameters in a method?
-
pandas_ai.save_charts(True, path='user/specifed/path')
@gventuri I'm curious to know your thoughts?
@sandiemann Yes, I think that's a good idea to create a separate issue about the file path problems on Unix.
I personally don't like the idea of adding another parameter, because I think it clutters the interface. Alternatively we could accept a file path as a variable to the existing parameter. (does feel overloaded)
* `pandas_ai = PandasAI(llm, save_charts='user/specified/path')`
Or perhaps set save chart parameters in a method?
* `pandas_ai.save_charts(True, path='user/specifed/path')`
@gventuri I'm curious to know your thoughts?
@jonbiemond yes that is what I meant actually, a parameter that takes a desired output path for charts not additional sorry. Agree, we don't want to overload. we wait for @gventuri feedback on this one.
@sandiemann thanks a lot for pointing out, closing!