mdik1 commited on
Commit
0ff1bba
·
verified ·
1 Parent(s): d48df04

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +77 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from crewai import Agent, Task, Crew
3
+ from langchain_groq import ChatGroq
4
+ import streamlit as st
5
+
6
+ # Initialize the LLM for the Marketing Research Agent
7
+ llm = ChatGroq(
8
+ groq_api_key="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",
9
+ model_name="llama3-70b-8192", # Replace with the actual Marketing Research model name
10
+ )
11
+
12
+ # Define the Marketing Research Agent with a specific goal
13
+ marketing_agent = Agent(
14
+ role='Marketing Research Agent',
15
+ goal='Provide in-depth insights and analysis on marketing trends, strategies, consumer behavior, and market research.',
16
+ backstory=(
17
+ "You are a Marketing Research Agent, skilled in gathering and analyzing information on market trends, "
18
+ "consumer behavior, competitive landscape, and marketing strategies. Your role is to answer marketing-related questions "
19
+ "with a detailed, data-driven approach, and strictly limit responses to marketing research only."
20
+ ),
21
+ verbose=True,
22
+ llm=llm,
23
+ )
24
+
25
+ def process_question_with_agent(question):
26
+ # Describe the task for the agent
27
+ task_description = f"Research and provide a detailed answer to the marketing question: '{question}'"
28
+
29
+ # Define the task for the agent to generate a response to the question
30
+ research_task = Task(
31
+ description=task_description,
32
+ agent=marketing_agent,
33
+ human_input=False,
34
+ expected_output="Answer related to marketing research" # Placeholder for expected output
35
+ )
36
+
37
+ # Instantiate the crew with the defined agent and task
38
+ crew = Crew(
39
+ agents=[marketing_agent],
40
+ tasks=[research_task],
41
+ verbose=2,
42
+ )
43
+
44
+ # Get the crew to work on the task and return the result
45
+ result = crew.kickoff()
46
+
47
+ return result
48
+
49
+ # Set the title of your app with Markdown
50
+ st.markdown("<h1 style='text-align: center;'>Marketing Research Chatbot</h1>", unsafe_allow_html=True)
51
+
52
+ # Initialize chat history
53
+ if "messages" not in st.session_state:
54
+ st.session_state.messages = []
55
+
56
+ # Display chat messages from history on app rerun
57
+ for message in st.session_state.messages:
58
+ with st.chat_message(message["role"]):
59
+ st.markdown(message["content"])
60
+
61
+ # React to user input
62
+ if prompt := st.chat_input("Ask a marketing research question:"):
63
+ # Display user message in chat message container
64
+ st.chat_message("user").markdown(prompt)
65
+ # Add user message to chat history
66
+ st.session_state.messages.append({"role": "user", "content": prompt})
67
+
68
+ # Get the response from the Marketing Research Agent
69
+ with st.spinner("Processing..."):
70
+ response = process_question_with_agent(prompt)
71
+
72
+ # Display assistant response in chat message container
73
+ with st.chat_message("assistant"):
74
+ st.markdown(response)
75
+
76
+ # Add assistant response to chat history
77
+ st.session_state.messages.append({"role": "assistant", "content": response})
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ crewai==0.30.11
2
+ langchain_groq==0.1.5
3
+ streamlit==1.31.0
4
+ Pillow==10.2.0