Sinaptik-AI / pandas-ai

Chat with your database (SQL, CSV, pandas, polars, mongodb, noSQL, etc). PandasAI makes data analysis conversational using LLMs (GPT 3.5 / 4, Anthropic, VertexAI) and RAG.
https://pandas-ai.com
Other
12.99k stars 1.25k forks source link

Problem when deploying to Streamlit: No module named 'pandasai.responses' #649

Closed phildental closed 1 year ago

phildental commented 1 year ago

🐛 Describe the bug

Error: Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script

    exec(code, module.__dict__)

  File "/mount/src/whitelabel-llm-agents/personal-finance.py", line 7, in <module>

    from pandasai.responses import StreamlitResponse

ModuleNotFoundError: No module named 'pandasai.responses'

Code:

import pandas as pd
import requests
import streamlit as st
import os
from pandasai.llm import OpenAI
from pandasai import SmartDataframe
from pandasai.responses import StreamlitResponse
from pandasai.helpers.openai_info import get_openai_callback
from dotenv import load_dotenv

load_dotenv()
GS_API = os.getenv('GS_API')
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')

# Send a request to the API and get the response
response = requests.get(GS_API)

# Parse the JSON data
data = response.json()

# Normalize the data and create a DataFrame
dfnor = pd.json_normalize(data)

#Clear empty rows
df = dfnor[dfnor['hash'] != ""]

def main():
    llm = OpenAI(api_token=OPENAI_API_KEY, temperature=0)
    sdf = SmartDataframe(df, config={"llm": llm, "verbose": True, "response_parser": StreamlitResponse, "max_retries": 10})
    st.set_page_config(
        page_title="You Personal Finance Assistant 🧞‍♂️",
        page_icon=":sales:",
        layout="centered"
        )

    st.header("Hi, I am PennyPal! 🧞‍♂️💰")
    user_question = st.text_input("Ask me a question about your finances.")
    if user_question is not None and user_question != "":
        with get_openai_callback() as cb:
            output = sdf.chat(user_question)
            st.write(output)
            st.write(cb)

if __name__ == '__main__':
    main()

requirements.txt:

duckdb==0.9.1
pandasai==1.3.3
pandas=2.0.0
python==3.11.5
phildental commented 1 year ago

Found out the issue was with the cache from "enabled_cache": True.

On streamlit, the cache folder seems not "reachable" from the script.

gventuri commented 1 year ago

@phildental which version are you using? This issue should have been fixed with recent updates. Let me know :)

phildental commented 11 months ago

pandasai==1.3.3