Fozan-Talat commited on
Commit
795b56a
1 Parent(s): 9aa29f6

Initial commit

Browse files
Files changed (1) hide show
  1. app.py +179 -0
app.py ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ import warnings
4
+ warnings.filterwarnings('ignore')
5
+
6
+ from crewai import Agent, Task, Crew
7
+ from crewai_tools import (
8
+ #DirectoryReadTool,
9
+ #FileReadTool,
10
+ #SerperDevTool,
11
+ #WebsiteSearchTool,
12
+ #DOCXSearchTool,
13
+ #RagTool,
14
+ TXTSearchTool
15
+ )
16
+ from datetime import datetime
17
+
18
+
19
+ import os
20
+ from utils import get_openai_api_key
21
+
22
+
23
+ openai_api_key = get_openai_api_key()
24
+
25
+ os.environ["OPENAI_MODEL_NAME"] = 'gpt-3.5-turbo'
26
+ os.environ["OPENAI_API_KEY"] = "sk-proj-8nKBOgxInYCIqidcdSu7T3BlbkFJWac8qZbpFOE2TSn0OpId"
27
+
28
+
29
+ def call_crew_kickoff(str_current_datetime):
30
+ # Instantiate tools
31
+ #meeting_trans_docs_tool = DirectoryReadTool(directory='./meeting-transcription')
32
+ #brd_temp_docs_tool = DirectoryReadTool(directory='./brd-template')
33
+ #file_tool = FileReadTool()
34
+ #web_rag_tool = WebsiteSearchTool()
35
+ #docx_search_tool = DOCXSearchTool()
36
+ #rag_tool = RagTool()
37
+ mt_tool = TXTSearchTool(txt='./meeting-transcription/meeting-transcript_' + str_current_datetime + '.txt')
38
+ brd_tool = TXTSearchTool(txt='./brd-template/brd-template.txt')
39
+
40
+ text_parsing_agent = Agent(
41
+ role="Text Interpreter",
42
+ goal="Parse and interpret the raw text input, structuring it into manageable sections"
43
+ "or data points that are relevant for analysis and processing.",
44
+ backstory="You excel at deciphering complex textual data. You act as the first line of analysis,"
45
+ "turning unstructured text into organized segments. You should enhance efficiency in data"
46
+ "handling and support subsequent stages of data processing.",
47
+ tools=[mt_tool],
48
+ allow_delegation=True,
49
+ verbose=True
50
+ )
51
+
52
+ data_extraction_agent = Agent(
53
+ role="Data Extraction Agent",
54
+ goal="Identify and extract essential data points, statistics,"
55
+ "and specific information from the parsed text that are crucial"
56
+ "for drafting a Business Requirements Document.",
57
+ backstory="You should tackle the challenge of sifting through detailed textual data to"
58
+ "find relevant information. You should be doing it with precision and speed, equipped"
59
+ "with capabilities to recognize and categorize data efficiently, making it invaluable"
60
+ "for projects requiring quick turnaround and accurate data handling.",
61
+ tools=[mt_tool, brd_tool],
62
+ allow_delegation=True,
63
+ verbose=True
64
+ )
65
+
66
+ brd_compiler_agent = Agent(
67
+ role="BRD Compiler",
68
+ goal="Assemble the extracted data into a well-structured Business Requirements Document,"
69
+ "ensuring that it is clear, coherent, and formatted according to standards.",
70
+ backstory="You are a meticulous Business Requirement Document compiler, You should alleviate"
71
+ "the burdens of manual document assembly. Ensure that all documents are crafted with"
72
+ "precision, adhering to organizational standards, and ready for stakeholder review. You"
73
+ "should be automating routine documentation tasks, thus allowing human team members to focus"
74
+ "on more strategic activities.",
75
+ tools=[brd_tool],
76
+ allow_delegation=True,
77
+ verbose=True
78
+ )
79
+
80
+ text_parsing = Task(
81
+ description=(
82
+ "1. Open and read the contents of the input text file.\n"
83
+ "2. Analyze the document structure to identify headings, subheadings, and key paragraphs.\n"
84
+ "3. Extract text under each identified section, ensuring context is preserved.\n"
85
+ "4. Format the extracted text into a JSON structure with labels indicating the type"
86
+ "of content (e.g., heading, detail)."
87
+ ),
88
+ expected_output="Structured JSON object containing separated sections of"
89
+ "text with labels based on their content type.",
90
+ agent=text_parsing_agent,
91
+ )
92
+
93
+ data_extraction = Task(
94
+ description=(
95
+ "1. Take the JSON structured data from the Text Parsing Agent.\n"
96
+ "2. Identify and extract specific data points like project goals, technical requirements,"
97
+ "and stakeholder information.\n"
98
+ "3. Organize the extracted data into relevant categories for easy access and use.\n"
99
+ "4. Format all extracted data into a structured form suitable for document generation,"
100
+ "ensuring it's ready for template insertion.\n"
101
+ ),
102
+ expected_output="A comprehensive list of key data points organized by category, ready for use in document generation.",
103
+ agent=data_extraction_agent,
104
+ )
105
+
106
+ compile_brd = Task(
107
+ description=(
108
+ "1. Accept the structured and categorized data from the Data Extraction Agent.\n"
109
+ "2. Open and read the BRD template for data insertion.\n"
110
+ "3. Insert the received data into the respective sections of the BRD template.\n"
111
+ "4. Apply formatting rules to ensure the document is professional and adheres to standards.\n"
112
+ "5. Save the populated and formatted document as a new markdown file, marking the task as complete.\n"
113
+ ),
114
+ expected_output="A complete Business Requirements Document in markdown format, ready for review and distribution.",
115
+ agent=brd_compiler_agent,
116
+ output_file='generated-brd/brd_' + str_current_datetime + '.md', # The final blog post will be saved here
117
+ )
118
+
119
+ crew = Crew(
120
+ agents=[text_parsing_agent, data_extraction_agent, brd_compiler_agent],
121
+ tasks=[text_parsing, data_extraction, compile_brd],
122
+ verbose=2
123
+ )
124
+
125
+ result = crew.kickoff(inputs={'datetime': str_current_datetime})
126
+
127
+
128
+ import gradio as gr
129
+
130
+ def process_file(input_file):
131
+ current_datetime = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
132
+ print("Current date & time : ", current_datetime)
133
+
134
+ # convert datetime obj to string
135
+ str_current_datetime = str(current_datetime)
136
+
137
+ fh = open(input_file, 'rb')
138
+ #data = fh.read()
139
+
140
+ # Ensure the target directory exists
141
+ output_dir = "meeting-transcription"
142
+ if not os.path.exists(output_dir):
143
+ os.makedirs(output_dir)
144
+
145
+ # Save the uploaded file to the specified folder with the specified name
146
+ input_filepath = os.path.join(output_dir, "meeting-transcript_" + str_current_datetime + ".txt")
147
+ with open(input_filepath, "wb") as file:
148
+ file.write(fh.read())
149
+ fh.close()
150
+
151
+ call_crew_kickoff(str_current_datetime)
152
+
153
+ # Example of processing: adding Markdown formatting. Replace this with your actual processing.
154
+ #processed_text = "# Processed Output\n\n" + "\n".join(f"- {line}" for line in text.splitlines())
155
+
156
+ output_filename = "generated-brd/brd_" + str_current_datetime + ".md"
157
+ #with open(output_filename, "w") as file:
158
+ # file.write(processed_text)
159
+
160
+ # Read the contents of the generated Markdown file
161
+ with open(output_filename, "r") as md_file:
162
+ markdown_content = md_file.read()
163
+
164
+ # Return both the filename for download and the Markdown content for display
165
+ return output_filename, markdown_content
166
+
167
+ with gr.Blocks() as demo:
168
+ with gr.Row():
169
+ file_input = gr.File(label="Upload a text file")
170
+ download_btn = gr.File(label="Download Processed File in Markdown", file_count="single")
171
+ with gr.Row():
172
+ markdown_output = gr.Markdown()
173
+
174
+ file_input.change(process_file, inputs=file_input, outputs=[download_btn, markdown_output])
175
+
176
+ demo.launch(share=True)
177
+
178
+
179
+