Spaces:
Runtime error
Runtime error
Commit
·
498941b
1
Parent(s):
020db15
Update app.py
Browse files
app.py
CHANGED
@@ -26,6 +26,8 @@ from langchain.llms import OpenAI
|
|
26 |
from langchain.agents import create_pandas_dataframe_agent
|
27 |
import pandas as pd
|
28 |
import docx
|
|
|
|
|
29 |
|
30 |
|
31 |
|
@@ -42,6 +44,7 @@ stability_api = client.StabilityInference(
|
|
42 |
whisper_from_pipeline = pipeline("automatic-speech-recognition",model="openai/whisper-medium")
|
43 |
EMBEDIDNGS = None
|
44 |
DATAFRAME_FILE = None
|
|
|
45 |
DOCSEARCH = None
|
46 |
RANDOM_USER = ''.join(chr(random.randint(65,90)) for i in range(8))+f'{random.randint(1,10000000000)}'
|
47 |
print(f'{RANDOM_USER} chat started')
|
@@ -156,7 +159,7 @@ def search_document_uploaded(user_query:str) -> str:
|
|
156 |
|
157 |
|
158 |
def ask_dataframes(user_query):
|
159 |
-
return DATAFRAME_FILE.run(user_query)
|
160 |
|
161 |
############# GET OPENAI RESPONSE
|
162 |
def get_open_ai_reponse(user_query:str)->Union[tuple,str]:
|
@@ -307,18 +310,14 @@ def ask_questions_abt_dataframes(file,file_ext):
|
|
307 |
print(file_ext)
|
308 |
global EMBEDIDNGS
|
309 |
EMBEDIDNGS = None
|
310 |
-
global DOCSEARCH
|
311 |
-
DOCSEARCH = None
|
312 |
-
|
313 |
-
|
314 |
|
315 |
reader_function = { '.csv': pd.read_csv, '.xlsx': pd.read_excel }.get(file_ext)
|
316 |
print(reader_function.__name__)
|
317 |
global DATAFRAME_FILE
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
)
|
322 |
|
323 |
|
324 |
|
|
|
26 |
from langchain.agents import create_pandas_dataframe_agent
|
27 |
import pandas as pd
|
28 |
import docx
|
29 |
+
from pandasai import PandasAI
|
30 |
+
from pandasai.llm.openai import OpenAI as pai_openai
|
31 |
|
32 |
|
33 |
|
|
|
44 |
whisper_from_pipeline = pipeline("automatic-speech-recognition",model="openai/whisper-medium")
|
45 |
EMBEDIDNGS = None
|
46 |
DATAFRAME_FILE = None
|
47 |
+
DATAFRAME = None
|
48 |
DOCSEARCH = None
|
49 |
RANDOM_USER = ''.join(chr(random.randint(65,90)) for i in range(8))+f'{random.randint(1,10000000000)}'
|
50 |
print(f'{RANDOM_USER} chat started')
|
|
|
159 |
|
160 |
|
161 |
def ask_dataframes(user_query):
|
162 |
+
return DATAFRAME_FILE.run(DATAFRAME, prompt = user_query)
|
163 |
|
164 |
############# GET OPENAI RESPONSE
|
165 |
def get_open_ai_reponse(user_query:str)->Union[tuple,str]:
|
|
|
310 |
print(file_ext)
|
311 |
global EMBEDIDNGS
|
312 |
EMBEDIDNGS = None
|
|
|
|
|
|
|
|
|
313 |
|
314 |
reader_function = { '.csv': pd.read_csv, '.xlsx': pd.read_excel }.get(file_ext)
|
315 |
print(reader_function.__name__)
|
316 |
global DATAFRAME_FILE
|
317 |
+
global DATAFRAME
|
318 |
+
DATAFRAME = reader_function(file.name)
|
319 |
+
llm = pai_openai(api_token=os.environ['OPENAI_API_KEY'])
|
320 |
+
DATAFRAME_FILE = PandasAI(llm)
|
321 |
|
322 |
|
323 |
|