dljdd commited on
Commit
56efacd
1 Parent(s): 32884a1
Files changed (3) hide show
  1. app.py +195 -0
  2. groqcloud_darkmode.png +0 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import os
4
+ from crewai import Agent, Task, Crew
5
+ from langchain_groq import ChatGroq
6
+
7
+
8
+ def main():
9
+
10
+ # Set up the customization options
11
+ st.sidebar.title('Customization')
12
+ model = st.sidebar.selectbox(
13
+ 'Choose a model',
14
+ ['llama3-8b-8192', 'mixtral-8x7b-32768', 'gemma-7b-it']
15
+ )
16
+
17
+ llm = ChatGroq(
18
+ temperature=0,
19
+ groq_api_key = st.secrets["GROQ_API_KEY"],
20
+ model_name=model
21
+ )
22
+
23
+ # Streamlit UI
24
+ st.title('CrewAI Machine Learning Assistant')
25
+ multiline_text = """
26
+ The CrewAI Machine Learning Assistant is designed to guide users through the process of defining, assessing, and solving machine learning problems. It leverages a team of AI agents, each with a specific role, to clarify the problem, evaluate the data, recommend suitable models, and generate starter Python code. Whether you're a seasoned data scientist or a beginner, this application provides valuable insights and a head start in your machine learning projects.
27
+ """
28
+
29
+ st.markdown(multiline_text, unsafe_allow_html=True)
30
+
31
+ # Display the Groq logo
32
+ spacer, col = st.columns([5, 1])
33
+ with col:
34
+ st.image('groqcloud_darkmode.png')
35
+
36
+
37
+ Problem_Definition_Agent = Agent(
38
+ role='Problem_Definition_Agent',
39
+ goal="""clarify the machine learning problem the user wants to solve,
40
+ identifying the type of problem (e.g., classification, regression) and any specific requirements.""",
41
+ backstory="""You are an expert in understanding and defining machine learning problems.
42
+ Your goal is to extract a clear, concise problem statement from the user's input,
43
+ ensuring the project starts with a solid foundation.""",
44
+ verbose=True,
45
+ allow_delegation=False,
46
+ llm=llm,
47
+ )
48
+
49
+ Data_Assessment_Agent = Agent(
50
+ role='Data_Assessment_Agent',
51
+ goal="""evaluate the data provided by the user, assessing its quality,
52
+ suitability for the problem, and suggesting preprocessing steps if necessary.""",
53
+ backstory="""You specialize in data evaluation and preprocessing.
54
+ Your task is to guide the user in preparing their dataset for the machine learning model,
55
+ including suggestions for data cleaning and augmentation.""",
56
+ verbose=True,
57
+ allow_delegation=False,
58
+ llm=llm,
59
+ )
60
+
61
+ Model_Recommendation_Agent = Agent(
62
+ role='Model_Recommendation_Agent',
63
+ goal="""suggest the most suitable machine learning models based on the problem definition
64
+ and data assessment, providing reasons for each recommendation.""",
65
+ backstory="""As an expert in machine learning algorithms, you recommend models that best fit
66
+ the user's problem and data. You provide insights into why certain models may be more effective than others,
67
+ considering classification vs regression and supervised vs unsupervised frameworks.""",
68
+ verbose=True,
69
+ allow_delegation=False,
70
+ llm=llm,
71
+ )
72
+
73
+
74
+ Starter_Code_Generator_Agent = Agent(
75
+ role='Starter_Code_Generator_Agent',
76
+ goal="""generate starter Python code for the project, including data loading,
77
+ model definition, and a basic training loop, based on findings from the problem definitions,
78
+ data assessment and model recommendation""",
79
+ backstory="""You are a code wizard, able to generate starter code templates that users
80
+ can customize for their projects. Your goal is to give users a head start in their coding efforts.""",
81
+ verbose=True,
82
+ allow_delegation=False,
83
+ llm=llm,
84
+ )
85
+
86
+ # Summarization_Agent = Agent(
87
+ # role='Starter_Code_Generator_Agent',
88
+ # goal="""Summarize findings from each of the previous steps of the ML discovery process.
89
+ # Include all findings from the problem definitions, data assessment and model recommendation
90
+ # and all code provided from the starter code generator.
91
+ # """,
92
+ # backstory="""You are a seasoned data scientist, able to break down machine learning problems for
93
+ # less experienced practitioners, provide valuable insight into the problem and why certain ML models
94
+ # are appropriate, and write good, simple code to help get started on solving the problem.
95
+ # """,
96
+ # verbose=True,
97
+ # allow_delegation=False,
98
+ # llm=llm,
99
+ # )
100
+
101
+ user_question = st.text_input("Describe your ML problem:")
102
+ data_upload = False
103
+ uploaded_file = st.file_uploader("Upload a sample .csv of your data (optional)")
104
+ if uploaded_file is not None:
105
+ try:
106
+ # Attempt to read the uploaded file as a DataFrame
107
+ df = pd.read_csv(uploaded_file).head(5)
108
+
109
+ # If successful, set 'data_upload' to True
110
+ data_upload = True
111
+
112
+ # Display the DataFrame in the app
113
+ st.write("Data successfully uploaded and read as DataFrame:")
114
+ st.dataframe(df)
115
+ except Exception as e:
116
+ st.error(f"Error reading the file: {e}")
117
+
118
+ if user_question:
119
+
120
+ task_define_problem = Task(
121
+ description="""Clarify and define the machine learning problem,
122
+ including identifying the problem type and specific requirements.
123
+
124
+ Here is the user's problem:
125
+
126
+ {ml_problem}
127
+ """.format(ml_problem=user_question),
128
+ agent=Problem_Definition_Agent,
129
+ expected_output="A clear and concise definition of the machine learning problem."
130
+ )
131
+
132
+ if data_upload:
133
+ task_assess_data = Task(
134
+ description="""Evaluate the user's data for quality and suitability,
135
+ suggesting preprocessing or augmentation steps if needed.
136
+
137
+ Here is a sample of the user's data:
138
+
139
+ {df}
140
+
141
+ The file name is called {uploaded_file}
142
+
143
+ """.format(df=df.head(),uploaded_file=uploaded_file),
144
+ agent=Data_Assessment_Agent,
145
+ expected_output="An assessment of the data's quality and suitability, with suggestions for preprocessing or augmentation if necessary."
146
+ )
147
+ else:
148
+ task_assess_data = Task(
149
+ description="""The user has not uploaded any specific data for this problem,
150
+ but please go ahead and consider a hypothetical dataset that might be useful
151
+ for their machine learning problem.
152
+ """,
153
+ agent=Data_Assessment_Agent,
154
+ expected_output="A hypothetical dataset that might be useful for the user's machine learning problem, along with any necessary preprocessing steps."
155
+ )
156
+
157
+ task_recommend_model = Task(
158
+ description="""Suggest suitable machine learning models for the defined problem
159
+ and assessed data, providing rationale for each suggestion.""",
160
+ agent=Model_Recommendation_Agent,
161
+ expected_output="A list of suitable machine learning models for the defined problem and assessed data, along with the rationale for each suggestion."
162
+ )
163
+
164
+
165
+ task_generate_code = Task(
166
+ description="""Generate starter Python code tailored to the user's project using the model recommendation agent's recommendation(s),
167
+ including snippets for package import, data handling, model definition, and training
168
+ """,
169
+ agent=Starter_Code_Generator_Agent,
170
+ expected_output="Python code snippets for package import, data handling, model definition, and training, tailored to the user's project, plus a brief summary of the problem and model recommendations."
171
+ )
172
+
173
+ # task_summarize = Task(
174
+ # description="""
175
+ # Summarize the results of the problem definition, data assessment, model recommendation and starter code generator.
176
+ # Keep the summarization brief and don't forget to share the entirety of the starter code!
177
+ # """,
178
+ # agent=Summarization_Agent
179
+ # )
180
+
181
+
182
+ crew = Crew(
183
+ agents=[Problem_Definition_Agent, Data_Assessment_Agent, Model_Recommendation_Agent, Starter_Code_Generator_Agent], #, Summarization_Agent],
184
+ tasks=[task_define_problem, task_assess_data, task_recommend_model, task_generate_code], #, task_summarize],
185
+ verbose=2
186
+ )
187
+
188
+ result = crew.kickoff()
189
+
190
+ st.write(result)
191
+
192
+
193
+ if __name__ == "__main__":
194
+ main()
195
+
groqcloud_darkmode.png ADDED
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit==1.31.0
2
+ crewai==0.1.32
3
+ pandas==1.5.1
4
+ langchain-groq==0.0.1