File size: 7,572 Bytes
edf6d57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180


import warnings
warnings.filterwarnings('ignore')

from crewai import Agent, Task, Crew
from crewai_tools import (
    #DirectoryReadTool,
    #FileReadTool,
    #SerperDevTool,
    #WebsiteSearchTool,
    #DOCXSearchTool,
    #RagTool,
    TXTSearchTool
)
from datetime import datetime


import os
from utils import get_openai_api_key


openai_api_key = get_openai_api_key()

os.environ["OPENAI_MODEL_NAME"] = 'gpt-3.5-turbo'
os.environ["OPENAI_API_KEY"] = "sk-proj-8nKBOgxInYCIqidcdSu7T3BlbkFJWac8qZbpFOE2TSn0OpId"


def call_crew_kickoff(str_current_datetime):
     # Instantiate tools
     #meeting_trans_docs_tool = DirectoryReadTool(directory='./meeting-transcription')
     #brd_temp_docs_tool = DirectoryReadTool(directory='./brd-template')
     #file_tool = FileReadTool()
     #web_rag_tool = WebsiteSearchTool()
     #docx_search_tool = DOCXSearchTool()
     #rag_tool = RagTool()
     mt_tool = TXTSearchTool(txt='./meeting-transcription/meeting-transcript_' + str_current_datetime + '.txt')
     brd_tool = TXTSearchTool(txt='./brd-template/brd-template.txt')

     text_parsing_agent = Agent(
        role="Text Interpreter",
        goal="Parse and interpret the raw text input, structuring it into manageable sections"
            "or data points that are relevant for analysis and processing.",
        backstory="You excel at deciphering complex textual data. You act as the first line of analysis,"
            "turning unstructured text into organized segments. You should enhance efficiency in data"
            "handling and support subsequent stages of data processing.",
        tools=[mt_tool],
        allow_delegation=True,
            verbose=True
     )

     data_extraction_agent = Agent(
          role="Data Extraction Agent",
          goal="Identify and extract essential data points, statistics,"
               "and specific information from the parsed text that are crucial"
               "for drafting a Business Requirements Document.",
          backstory="You should tackle the challenge of sifting through detailed textual data to"
               "find relevant information. You should be doing it with precision and speed, equipped"
               "with capabilities to recognize and categorize data efficiently, making it invaluable"
               "for projects requiring quick turnaround and accurate data handling.",
          tools=[mt_tool, brd_tool],
          allow_delegation=True,
          verbose=True
     )

     brd_compiler_agent = Agent(
          role="BRD Compiler",
          goal="Assemble the extracted data into a well-structured Business Requirements Document,"
               "ensuring that it is clear, coherent, and formatted according to standards.",
          backstory="You are a meticulous Business Requirement Document compiler, You should alleviate"
               "the burdens of manual document assembly. Ensure that all documents are crafted with"
               "precision, adhering to organizational standards, and ready for stakeholder review. You"
               "should be automating routine documentation tasks, thus allowing human team members to focus"
               "on more strategic activities.",
          tools=[brd_tool],
          allow_delegation=True,
          verbose=True
     )

     text_parsing = Task(
        description=(
            "1. Open and read the contents of the input text file.\n"
            "2. Analyze the document structure to identify headings, subheadings, and key paragraphs.\n"
            "3. Extract text under each identified section, ensuring context is preserved.\n"
            "4. Format the extracted text into a JSON structure with labels indicating the type"
                "of content (e.g., heading, detail)."
        ),
        expected_output="Structured JSON object containing separated sections of"
                        "text with labels based on their content type.",
        agent=text_parsing_agent,
     )

     data_extraction = Task(
        description=(
            "1. Take the JSON structured data from the Text Parsing Agent.\n"
            "2. Identify and extract specific data points like project goals, technical requirements,"
                "and stakeholder information.\n"
            "3. Organize the extracted data into relevant categories for easy access and use.\n"
            "4. Format all extracted data into a structured form suitable for document generation,"
                "ensuring it's ready for template insertion.\n"
        ),
        expected_output="A comprehensive list of key data points organized by category, ready for use in document generation.",
        agent=data_extraction_agent,
     )

     compile_brd = Task(
        description=(
            "1. Accept the structured and categorized data from the Data Extraction Agent.\n"
            "2. Open and read the BRD template for data insertion.\n"
            "3. Insert the received data into the respective sections of the BRD template.\n"
            "4. Apply formatting rules to ensure the document is professional and adheres to standards.\n"
            "5. Save the populated and formatted document as a new markdown file, marking the task as complete.\n"
        ),
        expected_output="A complete Business Requirements Document in markdown format, ready for review and distribution.",
        agent=brd_compiler_agent,
        output_file='generated-brd/brd_' + str_current_datetime + '.md',  # The final blog post will be saved here
     )

     crew = Crew(
        agents=[text_parsing_agent, data_extraction_agent, brd_compiler_agent],
        tasks=[text_parsing, data_extraction, compile_brd],
        verbose=2
     )

     result = crew.kickoff(inputs={'datetime': str_current_datetime})


import gradio as gr

def process_file(input_file):
    current_datetime = datetime.now().strftime("%Y-%m-%d %H-%M-%S")
    print("Current date & time : ", current_datetime)
    
    # convert datetime obj to string
    str_current_datetime = str(current_datetime)

    fh = open(input_file, 'rb')
    #data = fh.read()

    # Ensure the target directory exists
    output_dir = "meeting-transcription"
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    
    # Save the uploaded file to the specified folder with the specified name
    input_filepath = os.path.join(output_dir, "meeting-transcript_" + str_current_datetime + ".txt")
    with open(input_filepath, "wb") as file:
        file.write(fh.read())
    fh.close()

    call_crew_kickoff(str_current_datetime)

    # Example of processing: adding Markdown formatting. Replace this with your actual processing.
    #processed_text = "# Processed Output\n\n" + "\n".join(f"- {line}" for line in text.splitlines())
    
    output_filename = "generated-brd/brd_" + str_current_datetime + ".md"
    #with open(output_filename, "w") as file:
    #    file.write(processed_text)

    # Read the contents of the generated Markdown file
    with open(output_filename, "r") as md_file:
        markdown_content = md_file.read()

    # Return both the filename for download and the Markdown content for display
    return output_filename, markdown_content

with gr.Blocks() as demo:
    with gr.Row():
        file_input = gr.File(label="Upload a text file")
        download_btn = gr.File(label="Download Processed File in Markdown", file_count="single")
    with gr.Row():
        markdown_output = gr.Markdown()

    file_input.change(process_file, inputs=file_input, outputs=[download_btn, markdown_output])

demo.launch(share=True)