aiscientist's picture
Update app.py
c4567e9 verified
raw
history blame
1.39 kB
import streamlit as st
import os
def main():
st.sidebar.title("OpenAI Settings")
openai_api_key = st.sidebar.text_input("Enter your OpenAI API Key", type="password")
os.environ['OPENAI_API_KEY'] = openai_api_key
st.title("Personal Assistant")
uploaded_file = st.file_uploader("Upload CSV file", type=["csv"])
if uploaded_file is None:
st.warning("Please upload a CSV file.")
st.stop() # Stop execution if no file uploaded
from langchain.llms.openai import OpenAI
from langchain.agents.agent_types import AgentType
#from langchain.agents import create_csv_agent
from langchain_experimental.agents import create_csv_agent
import time
llm = OpenAI(temperature=0)
agent = create_csv_agent(
llm,
uploaded_file,
verbose=False,
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
)
query = st.text_input("What would you like to know?")
if st.button("Ask"):
if query.strip() == "":
st.warning("Please enter a query.")
else:
start = time.time()
answer = agent.run(query)
end = time.time()
st.write(answer)
st.write(f"Answer (took {round(end - start, 2)} s.)")
# Add the image
st.image("chatbot.jpeg", caption="Chatbot", use_column_width=True)
if __name__ == "__main__":
main()