File size: 1,598 Bytes
fb16faf 585ff59 fcab892 585ff59 d3bcfda fb16faf 585ff59 fb16faf 585ff59 d3bcfda fb16faf d3bcfda 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
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
from langchain.llms import AzureOpenAI
import os
os.environ["OPENAI_API_TYPE"] = "azure"
os.environ["OPENAI_API_VERSION"] = "2023-03-15-preview"
os.environ["OPENAI_API_BASE"] = "https://api.hku.hk"
os.environ["OPENAI_API_KEY"] = ""
# Import Azure OpenAI
from langchain.llms import AzureOpenAI
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:")
llm = AzureOpenAI(
deployment_name="chatgpt",
model_name="chatgpt",
openai_api_key=user_api_key,
)
agent = create_pandas_dataframe_agent(
llm,
df,
verbose=True,
agent_type=AgentType.OPENAI_FUNCTIONS,
)
result = agent.run(text_prompt)
st.write(result)
|