Update app.py
Browse files
app.py
CHANGED
@@ -5,29 +5,32 @@ from langchain.agents.agent_types import AgentType
|
|
5 |
from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent
|
6 |
from langchain_openai import ChatOpenAI
|
7 |
|
|
|
|
|
|
|
8 |
st.title("Excel ChatBot")
|
9 |
st.subheader("Stack used: LangChain Agent, Streamlit, OpenAI LLM - by https://github.com/jaglinux", divider='rainbow')
|
10 |
|
11 |
-
uploaded_file = st.file_uploader("Choose a file", type=['csv','xlsx'])
|
12 |
if uploaded_file is None:
|
13 |
df = pd.read_csv("titanic.csv")
|
14 |
st.write("Default file uploaded, titanic.csv")
|
15 |
else:
|
16 |
-
# Can be used wherever a "file-like" object is accepted:
|
17 |
if uploaded_file.name.endswith(".csv"):
|
18 |
df = pd.read_csv(uploaded_file)
|
19 |
elif uploaded_file.name.endswith(".xlsx"):
|
20 |
df = pd.read_excel(uploaded_file)
|
21 |
st.dataframe(df, height=5)
|
22 |
|
|
|
23 |
agent = create_pandas_dataframe_agent(
|
24 |
-
ChatOpenAI(temperature=0),
|
25 |
df,
|
26 |
verbose=True,
|
27 |
agent_type=AgentType.OPENAI_FUNCTIONS,
|
28 |
)
|
|
|
29 |
if question := st.chat_input("Ask Question to the csv/xlsx provided"):
|
30 |
response = agent.invoke(question)
|
31 |
-
print(response['output'])
|
32 |
st.chat_message("user").markdown(question)
|
33 |
-
st.chat_message("assistant").markdown(response['output'])
|
|
|
5 |
from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent
|
6 |
from langchain_openai import ChatOpenAI
|
7 |
|
8 |
+
# Usa tu clave API de OpenAI aquí
|
9 |
+
openai_api_key = 'sk-proj-8bJsop8rpnJkkMYhmOzwT3BlbkFJmwOmcQLI0dznDLpQMmuY'
|
10 |
+
|
11 |
st.title("Excel ChatBot")
|
12 |
st.subheader("Stack used: LangChain Agent, Streamlit, OpenAI LLM - by https://github.com/jaglinux", divider='rainbow')
|
13 |
|
14 |
+
uploaded_file = st.file_uploader("Choose a file", type=['csv', 'xlsx'])
|
15 |
if uploaded_file is None:
|
16 |
df = pd.read_csv("titanic.csv")
|
17 |
st.write("Default file uploaded, titanic.csv")
|
18 |
else:
|
|
|
19 |
if uploaded_file.name.endswith(".csv"):
|
20 |
df = pd.read_csv(uploaded_file)
|
21 |
elif uploaded_file.name.endswith(".xlsx"):
|
22 |
df = pd.read_excel(uploaded_file)
|
23 |
st.dataframe(df, height=5)
|
24 |
|
25 |
+
# Crear el agente con el DataFrame cargado
|
26 |
agent = create_pandas_dataframe_agent(
|
27 |
+
ChatOpenAI(temperature=0, openai_api_key=openai_api_key),
|
28 |
df,
|
29 |
verbose=True,
|
30 |
agent_type=AgentType.OPENAI_FUNCTIONS,
|
31 |
)
|
32 |
+
|
33 |
if question := st.chat_input("Ask Question to the csv/xlsx provided"):
|
34 |
response = agent.invoke(question)
|
|
|
35 |
st.chat_message("user").markdown(question)
|
36 |
+
st.chat_message("assistant").markdown(response['output'])
|