Spaces:
Build error
Build error
Yvann commited on
Commit ·
99ece80
1
Parent(s): 0256f27
first implementation of csv agent
Browse files- src/chatbot_csv.py +10 -0
- src/modules/sidebar.py +2 -5
- src/modules/utils.py +2 -0
src/chatbot_csv.py
CHANGED
|
@@ -1,11 +1,14 @@
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
from dotenv import load_dotenv
|
|
|
|
| 4 |
|
| 5 |
from modules.history import ChatHistory
|
| 6 |
from modules.layout import Layout
|
| 7 |
from modules.utils import Utilities
|
| 8 |
from modules.sidebar import Sidebar
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def init():
|
| 11 |
load_dotenv()
|
|
@@ -28,6 +31,8 @@ def main():
|
|
| 28 |
history = ChatHistory()
|
| 29 |
sidebar.show_options()
|
| 30 |
|
|
|
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
try:
|
|
@@ -53,6 +58,11 @@ def main():
|
|
| 53 |
|
| 54 |
history.generate_messages(response_container)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
except Exception as e:
|
| 57 |
st.error(f"Error: {str(e)}")
|
| 58 |
|
|
|
|
| 1 |
import os
|
| 2 |
import streamlit as st
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
+
from io import BytesIO
|
| 5 |
|
| 6 |
from modules.history import ChatHistory
|
| 7 |
from modules.layout import Layout
|
| 8 |
from modules.utils import Utilities
|
| 9 |
from modules.sidebar import Sidebar
|
| 10 |
+
from langchain.agents import create_csv_agent
|
| 11 |
+
from langchain.chat_models import ChatOpenAI
|
| 12 |
|
| 13 |
def init():
|
| 14 |
load_dotenv()
|
|
|
|
| 31 |
history = ChatHistory()
|
| 32 |
sidebar.show_options()
|
| 33 |
|
| 34 |
+
uploaded_file_content = BytesIO(uploaded_file.getvalue())
|
| 35 |
+
|
| 36 |
|
| 37 |
|
| 38 |
try:
|
|
|
|
| 58 |
|
| 59 |
history.generate_messages(response_container)
|
| 60 |
|
| 61 |
+
if st.session_state["show_csv_agent"]:
|
| 62 |
+
query = st.text_input(label="Use CSV agent for precise information about the CSV file itself")
|
| 63 |
+
if query != "":
|
| 64 |
+
agent = create_csv_agent(ChatOpenAI(temperature=0), uploaded_file_content, verbose=True)
|
| 65 |
+
st.write(agent.run(query))
|
| 66 |
except Exception as e:
|
| 67 |
st.error(f"Error: {str(e)}")
|
| 68 |
|
src/modules/sidebar.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
from langchain.chat_models import ChatOpenAI
|
| 4 |
|
| 5 |
class Sidebar:
|
| 6 |
MODEL_OPTIONS = ["gpt-3.5-turbo", "gpt-4"]
|
|
@@ -44,9 +43,7 @@ class Sidebar:
|
|
| 44 |
def csv_agent_button(self):
|
| 45 |
st.session_state.setdefault("show_csv_agent", False)
|
| 46 |
if st.sidebar.button("CSV Agent"):
|
| 47 |
-
st.session_state["show_csv_agent"] =
|
| 48 |
-
else:
|
| 49 |
-
st.session_state["show_csv_agent"] = False
|
| 50 |
|
| 51 |
def show_options(self):
|
| 52 |
with st.sidebar.expander("🛠️ Tools", expanded=False):
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
|
|
|
|
| 3 |
|
| 4 |
class Sidebar:
|
| 5 |
MODEL_OPTIONS = ["gpt-3.5-turbo", "gpt-4"]
|
|
|
|
| 43 |
def csv_agent_button(self):
|
| 44 |
st.session_state.setdefault("show_csv_agent", False)
|
| 45 |
if st.sidebar.button("CSV Agent"):
|
| 46 |
+
st.session_state["show_csv_agent"] = not st.session_state["show_csv_agent"]
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def show_options(self):
|
| 49 |
with st.sidebar.expander("🛠️ Tools", expanded=False):
|
src/modules/utils.py
CHANGED
|
@@ -31,12 +31,14 @@ class Utilities:
|
|
| 31 |
"""
|
| 32 |
uploaded_file = st.sidebar.file_uploader("upload", type="csv", label_visibility="collapsed")
|
| 33 |
if uploaded_file is not None:
|
|
|
|
| 34 |
|
| 35 |
def show_user_file(uploaded_file):
|
| 36 |
file_container = st.expander("Your CSV file :")
|
| 37 |
shows = pd.read_csv(uploaded_file)
|
| 38 |
uploaded_file.seek(0)
|
| 39 |
file_container.write(shows)
|
|
|
|
| 40 |
|
| 41 |
show_user_file(uploaded_file)
|
| 42 |
else:
|
|
|
|
| 31 |
"""
|
| 32 |
uploaded_file = st.sidebar.file_uploader("upload", type="csv", label_visibility="collapsed")
|
| 33 |
if uploaded_file is not None:
|
| 34 |
+
|
| 35 |
|
| 36 |
def show_user_file(uploaded_file):
|
| 37 |
file_container = st.expander("Your CSV file :")
|
| 38 |
shows = pd.read_csv(uploaded_file)
|
| 39 |
uploaded_file.seek(0)
|
| 40 |
file_container.write(shows)
|
| 41 |
+
|
| 42 |
|
| 43 |
show_user_file(uploaded_file)
|
| 44 |
else:
|