Spaces:
Runtime error
Runtime error
Sumukh Bhalchandra Sule
commited on
Commit
·
036c417
1
Parent(s):
c7c87c7
Add application file
Browse files- app.py +33 -0
- holdings.csv +0 -0
- requirements.txt +5 -0
- trades.csv +0 -0
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import langchain
|
3 |
+
import os
|
4 |
+
import pandas as pd
|
5 |
+
from langchain.agents import create_pandas_dataframe_agent
|
6 |
+
from langchain.llms import OpenAI
|
7 |
+
import gradio as gr
|
8 |
+
from langchain import PromptTemplate
|
9 |
+
|
10 |
+
os.environ['REQUESTS_CA_BUNDLE'] = 'caadmin.netskope.com.crt'
|
11 |
+
|
12 |
+
os.environ['OPENAI_API_KEY']="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"
|
13 |
+
|
14 |
+
df_holdings = pd.read_csv("holdings.csv")
|
15 |
+
|
16 |
+
df_trades = pd.read_csv("trades.csv")
|
17 |
+
|
18 |
+
agent = create_pandas_dataframe_agent(OpenAI(temperature=0.0), [df_holdings,df_trades], verbose=True,agent_executor_kwargs={"handle_parsing_errors": True})
|
19 |
+
openai = OpenAI(temperature=0.0,model="gpt-3.5-turbo",max_tokens=1000,top_p=1,top_k=0)
|
20 |
+
|
21 |
+
template = """Answer the question based on the context. Dont make your own questions. If the question is not related to dataframe strictly generate Final Answer as "Sorry can not find the answer".Question: {query}"""
|
22 |
+
|
23 |
+
prompt_template = PromptTemplate(
|
24 |
+
input_variables=["query"],
|
25 |
+
template=template
|
26 |
+
)
|
27 |
+
|
28 |
+
def chatbot(message,history):
|
29 |
+
output = agent(prompt_template.format(query=message))['output']
|
30 |
+
print(output)
|
31 |
+
return output
|
32 |
+
|
33 |
+
gr.ChatInterface(chatbot).launch()
|
holdings.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain
|
2 |
+
openai
|
3 |
+
gradio
|
4 |
+
pandas
|
5 |
+
tabulate
|
trades.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|