Download app.py from PRRMCP/RFPresponse: direct link, hf CLI and curl.
- Browser
- Download file 6.38 kB
-
https://huggingface.co/PRRMCP/RFPresponse/resolve/main/app.py
- Command line
-
hf download hf://PRRMCP/RFPresponse/app.py
-
curl -L -o app.py https://huggingface.co/PRRMCP/RFPresponse/resolve/main/app.py
6.38 kB
| # 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() | |