Spaces:
Sleeping
Sleeping
Upload 10 files
Browse files- .gitattributes +2 -0
- KB.csv +0 -0
- app_crew_with_web.py +173 -0
- db/1402aacf-da7d-4255-8d9b-5fdc847261d7/data_level0.bin +3 -0
- db/1402aacf-da7d-4255-8d9b-5fdc847261d7/header.bin +3 -0
- db/1402aacf-da7d-4255-8d9b-5fdc847261d7/index_metadata.pickle +3 -0
- db/1402aacf-da7d-4255-8d9b-5fdc847261d7/length.bin +3 -0
- db/1402aacf-da7d-4255-8d9b-5fdc847261d7/link_lists.bin +3 -0
- db/chroma.sqlite3 +3 -0
- knowledge/Master List 1-2-25.xlsx +3 -0
- requirements.txt +5 -0
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
db/chroma.sqlite3 filter=lfs diff=lfs merge=lfs -text
|
37 |
+
knowledge/Master[[:space:]]List[[:space:]]1-2-25.xlsx filter=lfs diff=lfs merge=lfs -text
|
KB.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
app_crew_with_web.py
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import time
|
3 |
+
from crewai import Agent, Task, Crew, Process
|
4 |
+
from langchain.llms import OpenAI
|
5 |
+
from textwrap import dedent
|
6 |
+
from langchain_openai import ChatOpenAI
|
7 |
+
from crewai_tools import CSVSearchTool
|
8 |
+
from crewai.knowledge.source.excel_knowledge_source import ExcelKnowledgeSource
|
9 |
+
|
10 |
+
import nest_asyncio
|
11 |
+
import os
|
12 |
+
from crewai.tools import BaseTool
|
13 |
+
from langchain_community.tools import DuckDuckGoSearchRun
|
14 |
+
nest_asyncio.apply()
|
15 |
+
|
16 |
+
|
17 |
+
class MyCustomDuckDuckGoTool(BaseTool):
|
18 |
+
name: str = "DuckDuckGo Search Tool"
|
19 |
+
description: str = "Search the web for a given query."
|
20 |
+
|
21 |
+
def _run(self, query: str) -> str:
|
22 |
+
# Ensure the DuckDuckGoSearchRun is invoked properly.
|
23 |
+
duckduckgo_tool = DuckDuckGoSearchRun()
|
24 |
+
response = duckduckgo_tool.invoke(query)
|
25 |
+
return response
|
26 |
+
|
27 |
+
def _get_tool(self):
|
28 |
+
# Create an instance of the tool when needed
|
29 |
+
return MyCustomDuckDuckGoTool()
|
30 |
+
api_key = os.getenv("YOUR SECRET KEY")
|
31 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
32 |
+
|
33 |
+
st.set_page_config(
|
34 |
+
page_title="CrewAI Test !", page_icon=":flag-ca:")
|
35 |
+
st.title("CrewAI Test ! π")
|
36 |
+
st.header("Let's chat :star2:")
|
37 |
+
|
38 |
+
# uploaded_file = st.sidebar.file_uploader("Upload a file", key= "uploaded_file")
|
39 |
+
# docsearch_structured,docsearch_unstructured = lch.create_db_for_both()
|
40 |
+
st.form_submit_button("Please enter your OpenAI API key")
|
41 |
+
|
42 |
+
|
43 |
+
@st.cache_resource(show_spinner = "Loading search tools and kb...")
|
44 |
+
def prepare_search_tool_and_kb():
|
45 |
+
tool = CSVSearchTool(csv='KB.csv')
|
46 |
+
excel_source = ExcelKnowledgeSource(file_paths=["Master List 1-2-25.xlsx"])
|
47 |
+
Duck_search = MyCustomDuckDuckGoTool()
|
48 |
+
return tool,Duck_search,excel_source
|
49 |
+
|
50 |
+
@st.cache_resource(show_spinner = "Loading crew...")
|
51 |
+
def prepare_crew():
|
52 |
+
tool,Duck_search,excel_source = prepare_search_tool_and_kb()
|
53 |
+
|
54 |
+
agent_1 = Agent(
|
55 |
+
role=dedent((
|
56 |
+
"""
|
57 |
+
Data Knowdledge Agent.
|
58 |
+
""")),
|
59 |
+
backstory=dedent((
|
60 |
+
"""
|
61 |
+
An angent with the abiity to search the database return the relevant answer for the question.
|
62 |
+
""")),
|
63 |
+
goal=dedent((
|
64 |
+
"""
|
65 |
+
Get relevant answer about the question.
|
66 |
+
""")),
|
67 |
+
allow_delegation=False,
|
68 |
+
verbose=True,
|
69 |
+
# β Whether the agent execution should be in verbose mode
|
70 |
+
max_iter=3,
|
71 |
+
# β maximum number of iterations the agent can perform before being forced to give its best answer
|
72 |
+
llm=ChatOpenAI(model_name="gpt-4o-mini", temperature=0),
|
73 |
+
tools = [tool],
|
74 |
+
)
|
75 |
+
|
76 |
+
agent_2 = Agent(
|
77 |
+
role=dedent((
|
78 |
+
"""
|
79 |
+
Web Search Agent.
|
80 |
+
""")),
|
81 |
+
backstory=dedent((
|
82 |
+
"""
|
83 |
+
An angent with the abiity to search search the web for the relevant information based on the asked question.
|
84 |
+
""")),
|
85 |
+
goal=dedent((
|
86 |
+
"""
|
87 |
+
Get relevant answer about the question.
|
88 |
+
""")),
|
89 |
+
allow_delegation=False,
|
90 |
+
verbose=False,
|
91 |
+
# β Whether the agent execution should be in verbose mode
|
92 |
+
max_iter=3,
|
93 |
+
# β maximum number of iterations the agent can perform before being forced to give its best answer
|
94 |
+
llm=ChatOpenAI(model_name="gpt-4o-mini", temperature=0),
|
95 |
+
tool=[Duck_search]
|
96 |
+
)
|
97 |
+
|
98 |
+
|
99 |
+
|
100 |
+
|
101 |
+
task_1 = Task(
|
102 |
+
description=dedent((
|
103 |
+
"""
|
104 |
+
Analyze the csv file and get all the relevant information for the following question.
|
105 |
+
|
106 |
+
Question: {question}
|
107 |
+
|
108 |
+
Make sure to get all the relevant data if there are more than one results.
|
109 |
+
|
110 |
+
Aggerate results into a single output.
|
111 |
+
""")),
|
112 |
+
expected_output=dedent((
|
113 |
+
"""
|
114 |
+
A detailed data answer to the question.
|
115 |
+
""")),
|
116 |
+
agent=agent_1,
|
117 |
+
)
|
118 |
+
|
119 |
+
task_2 = Task(
|
120 |
+
description=dedent((
|
121 |
+
"""
|
122 |
+
Search for the following question in the web.
|
123 |
+
|
124 |
+
Question: {question}
|
125 |
+
|
126 |
+
Make sure to get all the relevant data if there are more than one results.
|
127 |
+
|
128 |
+
Aggerate results into a single output.
|
129 |
+
""")),
|
130 |
+
expected_output=dedent((
|
131 |
+
"""
|
132 |
+
A detailed data answer to the question.
|
133 |
+
""")),
|
134 |
+
agent=agent_2,
|
135 |
+
)
|
136 |
+
|
137 |
+
crew = Crew(agents =[agent_1,agent_2],
|
138 |
+
tasks =[task_1,task_2],verbose=True, # You can set it to True or False
|
139 |
+
# β indicates the verbosity level for logging during execution.
|
140 |
+
process=Process.sequential,
|
141 |
+
knowledge_sources = [excel_source]
|
142 |
+
# β the process flow that the crew will follow (e.g., sequential, hierarchical).
|
143 |
+
)
|
144 |
+
return crew
|
145 |
+
|
146 |
+
crew = prepare_crew()
|
147 |
+
|
148 |
+
YES_MESSAGE = "Hello there, how can I help you today? "
|
149 |
+
|
150 |
+
if "messages" not in st.session_state.keys():
|
151 |
+
st.session_state.messages = [
|
152 |
+
{"role": "assistant", "content": YES_MESSAGE}
|
153 |
+
]
|
154 |
+
|
155 |
+
for message in st.session_state.messages: # Display the prior chat messages
|
156 |
+
with st.chat_message(message["role"]):
|
157 |
+
st.write(message["content"])
|
158 |
+
|
159 |
+
if prompt := st.chat_input("Your question"): # Prompt for user input and save to chat history
|
160 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
161 |
+
st.chat_message("user").write(prompt)
|
162 |
+
with st.chat_message("assistant"):
|
163 |
+
with st.spinner("Thinking..., please be patient"):
|
164 |
+
inputs ={"question":prompt}
|
165 |
+
response = crew.kickoff(inputs=inputs)
|
166 |
+
response_str = response.raw
|
167 |
+
# def generate():
|
168 |
+
# for text in response.response_gen:
|
169 |
+
# yield text
|
170 |
+
# time.sleep(0.05)
|
171 |
+
st.write(response_str)
|
172 |
+
message = {"role": "assistant", "content": response_str}
|
173 |
+
st.session_state.messages.append(response_str)
|
db/1402aacf-da7d-4255-8d9b-5fdc847261d7/data_level0.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:03cf11ed3b02b0beb38708ee4616f6bb6bf8817831086c7018f08f0cd8cb1fa0
|
3 |
+
size 150816000
|
db/1402aacf-da7d-4255-8d9b-5fdc847261d7/header.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f544106bbf645c6f2c185e02858dff76b9b62a2eed3249283c9560fc61babd60
|
3 |
+
size 100
|
db/1402aacf-da7d-4255-8d9b-5fdc847261d7/index_metadata.pickle
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:baf690fe08549ff6eb34a7b47427e355ebc741188fd3eaceb20a91e53a5efdc5
|
3 |
+
size 2446423
|
db/1402aacf-da7d-4255-8d9b-5fdc847261d7/length.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dd2261c65626b412446e38cfdbe5fa48a917bd7db67d3c32091b7bd79d297e41
|
3 |
+
size 96000
|
db/1402aacf-da7d-4255-8d9b-5fdc847261d7/link_lists.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0ea1f57997a9259f9723eb22b3fcb111c525ac14a7ccdc05d9c3b93b57a5f620
|
3 |
+
size 203304
|
db/chroma.sqlite3
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:111b57c93f30e685d7ee6e5f15a5a527c7ff4969152da021284bed47e7881a2e
|
3 |
+
size 59088896
|
knowledge/Master List 1-2-25.xlsx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7e6ccbd70c349cea34821fc827406d025840f0beaa265fe0927337350ae538ce
|
3 |
+
size 1248538
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pip==24.0
|
2 |
+
streamlit==1.32.2
|
3 |
+
python-dotenv==0.21.0
|
4 |
+
crewai==0.95.0
|
5 |
+
crewai-tools
|