File size: 6,384 Bytes
c5c4ac8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4196424
c5c4ac8
 
 
 
 
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
# app.py
from docx import Document
from docx.shared import Pt
from io import BytesIO
from base64 import b64encode
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
import gradio as gr
from huggingface_hub import InferenceClient

# Initialize Hugging Face Inference Client
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")

def generate_rfp_response_content(input_text):
    prompt = f"""
    Generate a response to the following RFP based on the provided input:
    {input_text}
    
    The response should include the following sections:
    1. Cover Letter: Write a cover letter addressed to the client, expressing appreciation for the opportunity to respond to the RFP and outlining the key points of the response.
    2. Executive Summary: Summarize the key elements of the response, highlighting the main points and benefits of choosing our company.
    3. Vendor Profile: Provide an overview of our company, including our history, mission, and key capabilities.
    4. Technical Approach: Detail our technical approach to the project, explaining how we will meet the requirements and deliver the desired outcomes.
    5. Project Plan: Outline our proposed project plan, including major milestones, timelines, and deliverables.
    6. Cost Proposal: Present our cost proposal, breaking down the costs associated with the project.
    7. Experience and References: Highlight our relevant experience and provide references from similar projects.
    8. Compliance and Certifications: Detail our compliance with the required standards and any relevant certifications we hold.
    9. Support and Maintenance: Explain our support and maintenance services post-implementation.
    10. Appendices: Include any additional information or documents relevant to the response.
    11. Timeline: This document outlines the project timeline, including major milestones and deliverables.
    12. Risk Management Plan: This document outlines our risk management approach, identifying potential risks and mitigation strategies.
    13. Change Request Form: This document provides a standardized form for requesting changes to the project scope, timeline, or budget.

    Non-Functional Requirements (Low Priority)
    4.1 Performance
    • The system should generate RFP responses within 1 minute.
    • The API should handle up to 100 concurrent requests.
    4.2 Scalability
    • The system should scale horizontally to accommodate increased load.
    4.3 Security
    • Ensure compliance with data protection regulations (e.g., GDPR, CCPA).
    • Implement robust authentication and authorization mechanisms.
    4.4 Reliability
    • The system should have an uptime of 99.9%.
    • Implement failover mechanisms to ensure high availability.
    4.5 Usability
    • The user interface should be intuitive and easy to navigate.
    • Provide comprehensive documentation and user guides.
    
    Ensure the content is in English, formatted with Times New Roman, Font size 12, black color.
    """
    
    response = client.chat_completion(
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": prompt}
        ],
        max_tokens=1500,
        temperature=0.7
    )
    
    content = response.choices[0].message.content
    
    # Remove Formatting Guidelines section if present
    if "Formatting Guidelines" in content:
        content = content.split("Formatting Guidelines")[0].strip()
    
    # Remove asterisks from the content
    content = content.replace("*", "")
    
    return content

def create_word_document(content):
    doc = Document()
    section_number = 1
    for line in content.split('\n'):
        if line.strip():
            # Check if the line starts with a section number
            if line.strip().startswith(str(section_number) + "."):
                paragraph = doc.add_paragraph(line.strip(), style="Heading 1")
                section_number += 1
            else:
                paragraph = doc.add_paragraph(line.strip())
            for run in paragraph.runs:
                run.font.name = 'Times New Roman'
                run.font.size = Pt(12)
    
    byte_io = BytesIO()
    doc.save(byte_io)
    byte_io.seek(0)
    return byte_io

def create_pdf_document(content):
    byte_io = BytesIO()
    doc = SimpleDocTemplate(byte_io, pagesize=letter)
    styles = getSampleStyleSheet()
    normal_style = styles["Normal"]
    normal_style.fontName = "Times-Roman"
    normal_style.fontSize = 12

    story = []
    section_number = 1
    for line in content.split('\n'):
        if line.strip():
            if line.strip().startswith(str(section_number) + "."):
                style_name = "Heading1"
                style = ParagraphStyle(name=style_name, parent=normal_style, fontSize=12, spaceAfter=12)
                story.append(Paragraph(line.strip(), style))
                section_number += 1
            else:
                story.append(Paragraph(line.strip(), normal_style))
            story.append(Spacer(1, 12))  # Add space between paragraphs
    
    doc.build(story)
    byte_io.seek(0)
    return byte_io

def generate_rfp(input_text):
    content = generate_rfp_response_content(input_text)
    
    word_io = create_word_document(content)
    pdf_io = create_pdf_document(content)
    
    word_base64 = b64encode(word_io.read()).decode('utf-8')
    pdf_base64 = b64encode(pdf_io.read()).decode('utf-8')
    
    word_link = f'<a href="data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,{word_base64}" download="RFP_Response.docx">Download Word Document</a>'
    pdf_link = f'<a href="data:application/pdf;base64,{pdf_base64}" download="RFP_Response.pdf">Download PDF Document</a>'
    
    return word_link, pdf_link

demo = gr.Interface(
    fn=generate_rfp,
    inputs=gr.Textbox(lines=7, placeholder="Enter specific input for the RFP response here..."),
    outputs=[
        gr.HTML(label="Download Word Document"),
        gr.HTML(label="Download PDF Document")
    ],
    title="AI-Driven RFP Response Generation (By Enlume Inc.)",
    description="Generate RFP response content using GPT4 model."
)

if __name__ == "__main__":
    demo.launch()