File size: 1,543 Bytes
fb16faf
 
 
 
 
0c20899
fb16faf
 
585ff59
d3bcfda
 
 
 
 
fb16faf
 
 
585ff59
fb16faf
 
 
 
 
 
 
 
 
 
 
 
 
 
585ff59
0c20899
79e72bb
0c20899
 
 
501f2ed
d3bcfda
fb16faf
 
708bf80
 
fb16faf
473ca9b
18de6d9
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
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
from langchain.chat_models.azure_openai import AzureChatOpenAI

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:")

    chat_model = AzureChatOpenAI(
        deployment_name="chatgpt-4-32k",
        openai_api_version="2023-03-15-preview",
        openai_api_type="azure",
        openai_api_base="https://api.hku.hk",
        openai_api_key="",
    )
    
    agent = create_pandas_dataframe_agent(
        llm=chat_model,
        df=df,
        verbose=True,
        max_tokens_limit=2048,
        handle_parsing_errors="Check your output and make sure it conforms!",
    )
    
    result = agent.run(text_prompt)
    st.write(result)