chore: Update Plotly dependency and improve graph generation in app.py
Browse files- app.py +14 -12
- requirements.txt +2 -1
app.py
CHANGED
@@ -51,7 +51,7 @@ class Agent:
|
|
51 |
def execute(self):
|
52 |
try:
|
53 |
response = self.client.chat.completions.create(
|
54 |
-
model="meta-llama/Meta-Llama-3.1-
|
55 |
stop=["PAUSE"],
|
56 |
messages=self.messages,
|
57 |
)
|
@@ -86,15 +86,17 @@ class Agent:
|
|
86 |
|
87 |
|
88 |
known_actions = {"runcode": runcode}
|
89 |
-
|
90 |
prompt = f"""
|
91 |
You are an expert in writing python code based on user request and you run in a loop of Thought, Action, PAUSE, Observation.
|
92 |
At the end of the loop you output an Answer
|
93 |
Use Thought to describe your thoughts about the question you have been asked.
|
94 |
Use Action to run one of the actions available to you - then return PAUSE.
|
95 |
Observation will be the result of running those actions.
|
|
|
|
|
|
|
|
|
96 |
Always return just code no need of ```
|
97 |
-
Always save generated plot as 'graph.png'
|
98 |
|
99 |
Your Task is help user get result of query about below dataset,Decide based on user query to make Plot or Just Textual Answer.
|
100 |
Here is the metadata of the dataset and name of dataset is customers-10000.csv:
|
@@ -110,8 +112,7 @@ runcode
|
|
110 |
How to use actions
|
111 |
Action : action_name: input_to_action
|
112 |
|
113 |
-
if
|
114 |
-
|
115 |
Example session:
|
116 |
|
117 |
Question: Get the average age of the customers
|
@@ -130,6 +131,7 @@ Observation : understand the output based its stdout and take necessary steps.
|
|
130 |
Answer: Final Answer for User Request if its graph send "Graph Generated" or Textual Answer "Your Interpretation of Answer"
|
131 |
""".strip()
|
132 |
|
|
|
133 |
bot = Agent(system_prompt=prompt, known_actions=known_actions)
|
134 |
|
135 |
st.set_page_config(layout="wide")
|
@@ -154,8 +156,8 @@ with col1:
|
|
154 |
if not query:
|
155 |
st.error("Please enter a query.")
|
156 |
else:
|
157 |
-
if "graph.
|
158 |
-
os.remove("graph.
|
159 |
st.session_state.logs = ""
|
160 |
with st.spinner("Generating response..."):
|
161 |
bot.query(query)
|
@@ -164,13 +166,13 @@ with col1:
|
|
164 |
answer_end_index = answer_match.end()
|
165 |
subsequent_text = st.session_state.logs[answer_end_index:].strip()
|
166 |
st.success(subsequent_text)
|
|
|
167 |
with col2:
|
168 |
st.header("Output")
|
169 |
-
if "graph.
|
170 |
-
|
171 |
-
st.image(image, caption="Generated Plot")
|
172 |
else:
|
173 |
st.write("No plot generated yet.")
|
174 |
|
175 |
-
st.
|
176 |
-
st.
|
|
|
51 |
def execute(self):
|
52 |
try:
|
53 |
response = self.client.chat.completions.create(
|
54 |
+
model="meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
|
55 |
stop=["PAUSE"],
|
56 |
messages=self.messages,
|
57 |
)
|
|
|
86 |
|
87 |
|
88 |
known_actions = {"runcode": runcode}
|
|
|
89 |
prompt = f"""
|
90 |
You are an expert in writing python code based on user request and you run in a loop of Thought, Action, PAUSE, Observation.
|
91 |
At the end of the loop you output an Answer
|
92 |
Use Thought to describe your thoughts about the question you have been asked.
|
93 |
Use Action to run one of the actions available to you - then return PAUSE.
|
94 |
Observation will be the result of running those actions.
|
95 |
+
|
96 |
+
|
97 |
+
for Graphing library use Plotly and save the plot as graph.html
|
98 |
+
Always save generated plot as 'graph.html'
|
99 |
Always return just code no need of ```
|
|
|
100 |
|
101 |
Your Task is help user get result of query about below dataset,Decide based on user query to make Plot or Just Textual Answer.
|
102 |
Here is the metadata of the dataset and name of dataset is customers-10000.csv:
|
|
|
112 |
How to use actions
|
113 |
Action : action_name: input_to_action
|
114 |
|
115 |
+
if input_to_action is code then don't use ``` just write code
|
|
|
116 |
Example session:
|
117 |
|
118 |
Question: Get the average age of the customers
|
|
|
131 |
Answer: Final Answer for User Request if its graph send "Graph Generated" or Textual Answer "Your Interpretation of Answer"
|
132 |
""".strip()
|
133 |
|
134 |
+
|
135 |
bot = Agent(system_prompt=prompt, known_actions=known_actions)
|
136 |
|
137 |
st.set_page_config(layout="wide")
|
|
|
156 |
if not query:
|
157 |
st.error("Please enter a query.")
|
158 |
else:
|
159 |
+
if "graph.html" in os.listdir():
|
160 |
+
os.remove("graph.html")
|
161 |
st.session_state.logs = ""
|
162 |
with st.spinner("Generating response..."):
|
163 |
bot.query(query)
|
|
|
166 |
answer_end_index = answer_match.end()
|
167 |
subsequent_text = st.session_state.logs[answer_end_index:].strip()
|
168 |
st.success(subsequent_text)
|
169 |
+
|
170 |
with col2:
|
171 |
st.header("Output")
|
172 |
+
if "graph.html" in os.listdir():
|
173 |
+
st.components.v1.html(open("graph.html", "r").read(), height=600)
|
|
|
174 |
else:
|
175 |
st.write("No plot generated yet.")
|
176 |
|
177 |
+
with st.expander("Logs"):
|
178 |
+
st.code(st.session_state.logs)
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
streamlit
|
2 |
openai
|
3 |
-
pillow
|
|
|
|
1 |
streamlit
|
2 |
openai
|
3 |
+
pillow
|
4 |
+
plotly
|