Spaces:
Sleeping
Sleeping
added the charts (#4)
Browse files- added the charts (644ca4672d57e67098cdabe6381098ea1351ad93)
app.py
CHANGED
@@ -13,13 +13,17 @@ import streamlit as st
|
|
13 |
from dotenv import load_dotenv
|
14 |
from sqlalchemy import create_engine, text, URL
|
15 |
from htmlTemplates import css, bot_template, user_template
|
16 |
-
|
17 |
-
import openai
|
18 |
import os
|
19 |
import time
|
20 |
-
|
21 |
-
from be import config, get_db_chain, outreach_sms_message, get_store_address
|
22 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def conversation_agent(question):
|
24 |
llm = ChatOpenAI(temperature=0.5, model="gpt-3.5-turbo") # create LLM
|
25 |
# search = DuckDuckGoSearchRun()
|
@@ -52,26 +56,41 @@ def conversation_agent(question):
|
|
52 |
name="Get Store Address",
|
53 |
func=get_store_address,
|
54 |
description="Use this tool with store number to get the store address. INPUT to this tool is Store number. Do not use this tool if you don't have Store number as input"
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
)
|
56 |
#tools.append(get_db_chain_tool)
|
57 |
# List all the tools for the agent to use
|
58 |
-
tools = [get_db_chain_tool, get_store_address_tool, outreach_sms_message_tool]
|
59 |
conversational_agent = initialize_agent(
|
60 |
agent="conversational-react-description",
|
61 |
tools=tools,
|
62 |
llm=llm,
|
63 |
verbose=True,
|
64 |
max_iterations=10,
|
|
|
65 |
memory=st.session_state.memory,
|
66 |
handle_parsing_errors=True
|
67 |
)
|
68 |
-
|
|
|
|
|
|
|
69 |
return response
|
70 |
|
|
|
|
|
|
|
|
|
71 |
def main():
|
|
|
72 |
img = Image.open('assist_logo.jpg')
|
73 |
-
|
74 |
-
|
75 |
load_dotenv() # load env parameters
|
76 |
st.set_page_config(page_title="Assist", page_icon=img)
|
77 |
st.write(css, unsafe_allow_html=True)
|
@@ -88,43 +107,47 @@ def main():
|
|
88 |
st.write("c. Send Text to Customers")
|
89 |
st.write("d. Search websites and look up Product prices & other info")
|
90 |
st.write("e. Generate charts for greater visualization")
|
91 |
-
|
92 |
if "chat_history" not in st.session_state:
|
93 |
st.session_state.memory = ConversationBufferMemory(memory_key="chat_history")
|
|
|
94 |
# ini chat history
|
95 |
if "messages" not in st.session_state:
|
96 |
st.session_state.messages = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
user_question = st.chat_input("Type your question")
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
chistory = assistant_response["chat_history"]
|
104 |
-
# Process the chat history
|
105 |
-
messages = chistory.split("Human: ")
|
106 |
-
l = len(messages)
|
107 |
-
# Step 3: Print the output
|
108 |
-
for i in range(1, l):
|
109 |
-
response = messages[i].strip()
|
110 |
-
response = response.split("AI:")
|
111 |
-
# Print the Human message from history
|
112 |
-
with st.chat_message("human"):
|
113 |
-
st.markdown(response[0])
|
114 |
-
# Print the AI message from history
|
115 |
-
with st.chat_message("ai"):
|
116 |
-
st.markdown(response[1])
|
117 |
-
#Print the last question from user
|
118 |
-
with st.chat_message("human"):
|
119 |
st.markdown(user_question)
|
120 |
-
|
|
|
|
|
|
|
121 |
# Print the last answer from user
|
122 |
-
|
123 |
-
with st.chat_message("
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
|
128 |
if __name__== '__main__':
|
129 |
main()
|
130 |
|
|
|
|
|
|
|
|
13 |
from dotenv import load_dotenv
|
14 |
from sqlalchemy import create_engine, text, URL
|
15 |
from htmlTemplates import css, bot_template, user_template
|
16 |
+
from openai import OpenAI
|
|
|
17 |
import os
|
18 |
import time
|
19 |
+
from be import config, get_db_chain, outreach_sms_message, get_store_address, data_visualization
|
|
|
20 |
from PIL import Image
|
21 |
+
from langchain_core.messages import HumanMessage, AIMessage
|
22 |
+
import matplotlib.pyplot as plt
|
23 |
+
import re
|
24 |
+
|
25 |
+
|
26 |
+
|
27 |
def conversation_agent(question):
|
28 |
llm = ChatOpenAI(temperature=0.5, model="gpt-3.5-turbo") # create LLM
|
29 |
# search = DuckDuckGoSearchRun()
|
|
|
56 |
name="Get Store Address",
|
57 |
func=get_store_address,
|
58 |
description="Use this tool with store number to get the store address. INPUT to this tool is Store number. Do not use this tool if you don't have Store number as input"
|
59 |
+
)
|
60 |
+
# create the tool for finding the store details
|
61 |
+
data_visualization_tool = Tool(
|
62 |
+
name="Data Visualization Tool",
|
63 |
+
func=data_visualization,
|
64 |
+
description="ONLY USE THIS TOOL for data visualization, do not create on your own. This tool is used to create python code to generate charts for data visualization with user question, column names, and pandas dataframe. DO NOT create sample dataframe, always use the provided dataframe in df. Always make sure the query generation tool is executed and the response is shown to the user before executing this tool"
|
65 |
)
|
66 |
#tools.append(get_db_chain_tool)
|
67 |
# List all the tools for the agent to use
|
68 |
+
tools = [get_db_chain_tool, get_store_address_tool, outreach_sms_message_tool, data_visualization_tool]
|
69 |
conversational_agent = initialize_agent(
|
70 |
agent="conversational-react-description",
|
71 |
tools=tools,
|
72 |
llm=llm,
|
73 |
verbose=True,
|
74 |
max_iterations=10,
|
75 |
+
return_intermediate_steps=True,
|
76 |
memory=st.session_state.memory,
|
77 |
handle_parsing_errors=True
|
78 |
)
|
79 |
+
|
80 |
+
#print(conversational_agent.agent.llm_chain.prompt.template)
|
81 |
+
#response = conversational_agent.invoke(question)
|
82 |
+
response = conversational_agent({"input": question})
|
83 |
return response
|
84 |
|
85 |
+
client = OpenAI()
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
def main():
|
90 |
+
st.set_option('deprecation.showPyplotGlobalUse', False)
|
91 |
img = Image.open('assist_logo.jpg')
|
92 |
+
# user_avatar = Image.open('renga_profile.jpg')
|
93 |
+
# ai_avatar = Image.open('Designer.png')
|
94 |
load_dotenv() # load env parameters
|
95 |
st.set_page_config(page_title="Assist", page_icon=img)
|
96 |
st.write(css, unsafe_allow_html=True)
|
|
|
107 |
st.write("c. Send Text to Customers")
|
108 |
st.write("d. Search websites and look up Product prices & other info")
|
109 |
st.write("e. Generate charts for greater visualization")
|
|
|
110 |
if "chat_history" not in st.session_state:
|
111 |
st.session_state.memory = ConversationBufferMemory(memory_key="chat_history")
|
112 |
+
st.session_state.chat_history = []
|
113 |
# ini chat history
|
114 |
if "messages" not in st.session_state:
|
115 |
st.session_state.messages = []
|
116 |
+
|
117 |
+
for message in st.session_state.chat_history:
|
118 |
+
if isinstance(message, HumanMessage):
|
119 |
+
with st.chat_message("Human"):
|
120 |
+
st.markdown(message.content)
|
121 |
+
else:
|
122 |
+
with st.chat_message("AI"):
|
123 |
+
st.markdown(message.content)
|
124 |
|
125 |
user_question = st.chat_input("Type your question")
|
126 |
+
|
127 |
+
if user_question is not None:
|
128 |
+
#Print the last question from user
|
129 |
+
with st.chat_message("Human"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
st.markdown(user_question)
|
131 |
+
|
132 |
+
with st.spinner("Processing"):
|
133 |
+
st.session_state.chat_history.append(HumanMessage(user_question))
|
134 |
+
|
135 |
# Print the last answer from user
|
136 |
+
|
137 |
+
with st.chat_message("AI"):
|
138 |
+
assistant_response = conversation_agent(user_question)
|
139 |
+
|
140 |
+
assistant_response_output = assistant_response["output"]
|
141 |
+
|
142 |
+
st.markdown(assistant_response_output)
|
143 |
+
|
144 |
+
st.session_state.chat_history.append(AIMessage(assistant_response_output))
|
145 |
+
|
146 |
|
147 |
|
148 |
if __name__== '__main__':
|
149 |
main()
|
150 |
|
151 |
+
#if st.button:
|
152 |
+
# question = "Top 3 sales in store 4057"
|
153 |
+
# output = data_visualization(question)
|