Spaces:
Runtime error
Runtime error
File size: 1,244 Bytes
fb16faf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import streamlit as st
from langchain.agents import create_pandas_dataframe_agent
from langchain.chat_models import ChatOpenAI
from langchain.agents.agent_types import AgentType
import pandas as pd
form = st.sidebar.form(key='my_form')
user_api_key = form.text_input(
label="#### Your OpenAI API key π",
placeholder="Paste your openAI API key, sk-",
type="password")
uploaded_file = form.file_uploader("Choose a file")
text_prompt = form.text_area('Text Prompt', value='Hello, how are you?')
submit_button = form.form_submit_button(label='Submit')
if submit_button :
df = pd.read_csv(uploaded_file)
st.title("OpenAI Chatbot π€"
)
st.subheader("This is a simple chatbot that uses OpenAI's GPT-3 model to generate responses to your text prompt. ")
st.subheader("Your data:")
st.write(df)
#horizontal line
st.markdown("""---""")
st.subheader("AI generated response:")
agent = create_pandas_dataframe_agent(
ChatOpenAI(temperature=0, model="gpt-3.5-turbo-16k", openai_api_key=user_api_key),
df,
verbose=True,
agent_type=AgentType.OPENAI_FUNCTIONS,
)
result = agent.run(text_prompt)
st.write(result)
|