Fozan-Talat commited on
Commit
8bb020e
·
1 Parent(s): b577c62
Files changed (1) hide show
  1. app.py +48 -122
app.py CHANGED
@@ -1,168 +1,94 @@
1
- import warnings
2
- warnings.filterwarnings('ignore')
3
-
4
- from crewai import Agent, Task, Crew, Process
5
- from crewai_tools import (
6
- FileReadTool,
7
- MDXSearchTool
8
- )
9
  from datetime import datetime
10
-
11
- import os
12
- import gradio as gr
13
  import mammoth
14
- import markdown
 
 
15
  from langchain_openai import ChatOpenAI
16
  from dotenv import load_dotenv
17
 
 
18
  load_dotenv()
19
 
20
  openai_api_key = os.getenv("openai_api_key")
21
  os.environ["OPENAI_MODEL_NAME"] = 'gpt-3.5-turbo'
22
  os.environ["OPENAI_API_KEY"] = openai_api_key
23
 
24
- with open('./brd-template/brd-template.md', 'r', encoding='utf-8') as file:
25
- brd_template_content = file.read()
26
- # Remove BOM character if it exists
27
- cleaned_brd_template = brd_template_content.replace('\ufeff', '')
28
 
29
- #print(cleaned_brd_template)
 
 
 
 
 
 
 
30
 
31
- def call_crew_kickoff(str_current_datetime):
32
- # Instantiate tools
33
- mt_tool = FileReadTool(txt='./meeting-transcription/meeting-transcript_' + str_current_datetime + '.md')
 
 
 
 
34
 
35
- semantic_search_resume = MDXSearchTool(mdx='./meeting-transcription/meeting-transcript_' + str_current_datetime + '.md')
 
 
 
36
 
37
- with open('./meeting-transcription/meeting-transcript_' + str_current_datetime + '.md', 'r', encoding='utf-8') as file:
38
  transcript_content = file.read()
39
- # Remove BOM character if it exists
40
  cleaned_transcript_content = transcript_content.replace('\ufeff', '')
41
 
 
 
 
 
42
  business_analyst = Agent(
43
  role="Business Analyst",
44
- goal="Effectively translate the meeting transcript and discussions into a well-structured BRD using the provided template, "
45
- "ensuring it accurately captures project requirements and stakeholder needs as per the template attached.",
46
  tools=[mt_tool, semantic_search_resume],
47
  allow_delegation=False,
48
  verbose=True,
49
- backstory=(
50
- "You come from a background in business analysis, with experience in similar IT projects or a strong understanding "
51
- "of the organization's needs. Your skillset includes: You can effectively guide discussions and ensure everyone is "
52
- "on the same page, even in a technical environment. You possess the ability to translate complex information into "
53
- "clear and concise written documents. You can analyze information effectively, identify key requirements, and prioritize "
54
- "them based on importance. You possess a strong understanding of the provided BRD template and its purpose."
55
- )
56
  )
57
 
58
  subject_matter_expert = Agent(
59
  role="Subject Matter Expert",
60
- goal="Ensure the BRD accurately reflects the project's technical feasibility and translates technical discussions into "
61
- "actionable requirements for a successful IT project. Additionally, propose a clear and concise project name that "
62
- "captures the essence of the initiative.",
63
  tools=[mt_tool, semantic_search_resume],
64
  allow_delegation=False,
65
  verbose=True,
66
- backstory=(
67
- "You possess in-depth knowledge and experience specific to the project's domain (data analytics and integrations). While "
68
- "not directly involved in the initial meeting discussions, your expertise is crucial for refining the BRD's technical aspects "
69
- "and ensuring stakeholder needs are addressed."
70
- )
71
  )
72
 
73
  analyze_meeting_for_brd = Task(
74
- description=(
75
- "###" + cleaned_transcript_content + "###\n"
76
- "Given above is the meeting transcript.\n"
77
- "1. Pay close attention to sections outlining functionalities, technical requirements, and references to specific technologies.\n"
78
- "2. Analyze the technical aspects discussed in the transcript (e.g., data processing infrastructure updates, cloud migration) and "
79
- "assess their feasibility. If needed, suggest alternative solutions or approaches to achieve the desired functionalities.\n"
80
- "3. Based on the transcript and your understanding of data analytics, translate the technical needs into clear and concise "
81
- "requirements within the BRD. This could include: \n"
82
- "Specific data points or sources needed for analysis.\n"
83
- "Functionality requirements for data ingestion, processing, and visualization.\n"
84
- "Integration requirements with existing systems.\n"
85
- "4. Review the stakeholder discussions in the transcript (e.g., IT team's need for robust backend support, marketing team's need "
86
- "for advanced analytics features). Ensure the BRD reflects these needs by outlining functionalities that address them.\n"
87
- "5. Familiarize yourself with the template's structure, sections, and required information for each section.\n"
88
- "6. Identify key points relevant to the BRD, focusing on project background, goals, functionalities, success criteria, risks, and "
89
- "stakeholder needs as per template ###\n" + cleaned_brd_template + "\n###.\n"
90
- "7. Fill in the appropriate sections of the BRD template using the information extracted from the transcript.\n"
91
- "8. Ensure consistency and clarity throughout the document. Check for completeness and address any missing information. Consider "
92
- "using the transcript to clarify details or resolve potential inconsistencies.\n"
93
- ),
94
- expected_output="A well-structured BRD, completed using the provided template, that accurately reflects the information captured in the "
95
- "meeting transcript. This includes clearly defined requirements, identified stakeholder needs, success criteria, and a preliminary "
96
- "understanding of project scope and risks.",
97
  agent=business_analyst,
98
  )
99
 
100
  sme_technical_review = Task(
101
- description=(
102
- "1. Pay close attention to sections outlining functionalities, technical requirements, and any references to specific technologies.\n"
103
- "2. Analyze whether the documented requirements align with technical constraints and capabilities. Identify any areas where the BRD "
104
- "might propose functionalities that are technically unrealistic or infeasible and add those in the BRD.\n"
105
- "3. If the BRD uses technical terms that might be unclear to non-technical stakeholders, propose alternative wording or explanations "
106
- "and update the BRD accordingly.\n"
107
- "4. Based on your expertise, anticipate and mention potential technical hurdles in the BRD that could arise during development based "
108
- "on the proposed requirements. Add mitigation strategies or alternative approaches in the BRD if necessary.\n"
109
- "5. Based on the project goals and functionalities discussed in the transcript, suggest a clear and concise name for the project. This "
110
- "name should accurately represent the initiative and be easily understood by all stakeholders."
111
- ),
112
- expected_output=("Comprehensive and refined BRD document including a proposed project name that captures the essence of the initiative."
113
- ),
114
  agent=subject_matter_expert,
115
  )
116
 
117
  crew = Crew(
118
- agents=[business_analyst, subject_matter_expert],
119
- tasks=[analyze_meeting_for_brd, sme_technical_review],
120
- verbose=2,
121
- manager_llm=ChatOpenAI(temperature=0, model="gpt-3.5-turbo"), # Mandatory for hierarchical process
122
- process=Process.hierarchical, # Specifies the hierarchical management approach
123
- memory=True, # Enable memory usage for enhanced task execution
124
  )
125
 
126
  result = crew.kickoff(inputs={'datetime': str_current_datetime})
127
 
128
  return result
129
-
130
-
131
- def process_file(input_file):
132
- if input_file is not None:
133
- current_datetime = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
134
- print("Current date & time : ", current_datetime)
135
-
136
- str_current_datetime = str(current_datetime)
137
- filename = 'meeting-transcription/meeting-transcript_' + str_current_datetime + '.md'
138
-
139
- with open(input_file, "rb") as docx_file:
140
- result = mammoth.convert_to_markdown(docx_file)
141
- with open(filename, 'w', encoding='utf-8') as f:
142
- f.write(result.value)
143
- f.close()
144
-
145
- response = call_crew_kickoff(str_current_datetime)
146
-
147
- output_filename = "generated-brd/generated-brd_" + str_current_datetime + ".md"
148
- with open(output_filename, 'w', encoding='utf-8') as f:
149
- f.write(response)
150
- f.close()
151
-
152
-
153
- return output_filename, response
154
-
155
-
156
- with gr.Blocks() as demo:
157
- with gr.Row():
158
- file_input = gr.File(label="Upload the meeting transcript (.docx file supported only)", file_types=[".docx"], file_count="single")
159
- download_btn = gr.File(label="Download Processed File in Markdown", file_count="single")
160
- with gr.Row():
161
- markdown_output = gr.Markdown()
162
-
163
- file_input.change(process_file, inputs=file_input, outputs=[download_btn, markdown_output])
164
-
165
- demo.launch()
166
-
167
-
168
-
 
1
+ from fastapi import FastAPI, File, UploadFile
2
+ from fastapi.responses import JSONResponse
 
 
 
 
 
 
3
  from datetime import datetime
 
 
 
4
  import mammoth
5
+ import os
6
+ from crewai import Agent, Task, Crew, Process
7
+ from crewai_tools import FileReadTool, MDXSearchTool
8
  from langchain_openai import ChatOpenAI
9
  from dotenv import load_dotenv
10
 
11
+ app = FastAPI()
12
  load_dotenv()
13
 
14
  openai_api_key = os.getenv("openai_api_key")
15
  os.environ["OPENAI_MODEL_NAME"] = 'gpt-3.5-turbo'
16
  os.environ["OPENAI_API_KEY"] = openai_api_key
17
 
18
+ @app.post("/upload")
19
+ async def upload_file(file: UploadFile = File(...)):
20
+ current_datetime = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
21
+ filename = f'meeting-transcription/meeting-transcript_{current_datetime}.md'
22
 
23
+ # Save file and convert to markdown
24
+ content = await file.read()
25
+ with open(f"{file.filename}", "wb") as docx_file:
26
+ docx_file.write(content)
27
+ with open(file.filename, "rb") as docx_file:
28
+ result = mammoth.convert_to_markdown(docx_file)
29
+ with open(filename, 'w', encoding='utf-8') as f:
30
+ f.write(result.value)
31
 
32
+ response = call_crew_kickoff(current_datetime)
33
+
34
+ output_filename = f"generated-brd/generated-brd_{current_datetime}.md"
35
+ with open(output_filename, 'w', encoding='utf-8') as f:
36
+ f.write(response)
37
+
38
+ return JSONResponse(content={"file_url": output_filename, "brd_content": response})
39
 
40
+ def call_crew_kickoff(str_current_datetime):
41
+ # Setup CrewAI agents and tasks
42
+ mt_tool = FileReadTool(txt=f'./meeting-transcription/meeting-transcript_{str_current_datetime}.md')
43
+ semantic_search_resume = MDXSearchTool(mdx=f'./meeting-transcription/meeting-transcript_{str_current_datetime}.md')
44
 
45
+ with open(f'./meeting-transcription/meeting-transcript_{str_current_datetime}.md', 'r', encoding='utf-8') as file:
46
  transcript_content = file.read()
 
47
  cleaned_transcript_content = transcript_content.replace('\ufeff', '')
48
 
49
+ with open('./brd-template/brd-template.md', 'r', encoding='utf-8') as file:
50
+ brd_template_content = file.read()
51
+ cleaned_brd_template = brd_template_content.replace('\ufeff', '')
52
+
53
  business_analyst = Agent(
54
  role="Business Analyst",
55
+ goal="Effectively translate the meeting transcript and discussions into a well-structured BRD...",
 
56
  tools=[mt_tool, semantic_search_resume],
57
  allow_delegation=False,
58
  verbose=True,
59
+ backstory="You come from a background in business analysis..."
 
 
 
 
 
 
60
  )
61
 
62
  subject_matter_expert = Agent(
63
  role="Subject Matter Expert",
64
+ goal="Ensure the BRD accurately reflects the project's technical feasibility...",
 
 
65
  tools=[mt_tool, semantic_search_resume],
66
  allow_delegation=False,
67
  verbose=True,
68
+ backstory="You possess in-depth knowledge and experience specific to the project's domain..."
 
 
 
 
69
  )
70
 
71
  analyze_meeting_for_brd = Task(
72
+ description="Analyze the meeting transcript and create a BRD...",
73
+ expected_output="A well-structured BRD...",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  agent=business_analyst,
75
  )
76
 
77
  sme_technical_review = Task(
78
+ description="Review the BRD for technical accuracy...",
79
+ expected_output="Comprehensive and refined BRD document...",
 
 
 
 
 
 
 
 
 
 
 
80
  agent=subject_matter_expert,
81
  )
82
 
83
  crew = Crew(
84
+ agents=[business_analyst, subject_matter_expert],
85
+ tasks=[analyze_meeting_for_brd, sme_technical_review],
86
+ verbose=2,
87
+ manager_llm=ChatOpenAI(temperature=0, model="gpt-3.5-turbo"),
88
+ process=Process.hierarchical,
89
+ memory=True,
90
  )
91
 
92
  result = crew.kickoff(inputs={'datetime': str_current_datetime})
93
 
94
  return result