Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,72 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
3 |
|
4 |
-
# Load the
|
5 |
generator = pipeline("text-generation", model="gpt2")
|
6 |
|
7 |
-
|
8 |
-
# Define the function to generate proposal text
|
9 |
def generate_proposal(client_description):
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
#
|
15 |
iface = gr.Interface(
|
16 |
fn=generate_proposal,
|
17 |
inputs=gr.Textbox(label="Client Requirement", placeholder="Describe the project or client needs here...", lines=5),
|
18 |
-
outputs=
|
|
|
|
|
|
|
|
|
19 |
title="AI Proposal Generator",
|
20 |
-
description="
|
21 |
)
|
22 |
|
23 |
-
# Launch the app
|
24 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
+
from fpdf import FPDF
|
4 |
+
import tempfile
|
5 |
+
import os
|
6 |
|
7 |
+
# Load the text-generation pipeline using GPT-2
|
8 |
generator = pipeline("text-generation", model="gpt2")
|
9 |
|
10 |
+
# Format the output as a business-style proposal
|
|
|
11 |
def generate_proposal(client_description):
|
12 |
+
# Generate raw text
|
13 |
+
raw = generator(f"{client_description}", max_length=300, do_sample=True, temperature=0.7)[0]['generated_text']
|
14 |
+
|
15 |
+
# Extract only the generated part (remove the prompt from output)
|
16 |
+
generated_only = raw.replace(client_description, "").strip()
|
17 |
+
|
18 |
+
# Build formatted text
|
19 |
+
formatted = f"""
|
20 |
+
PROJECT PROPOSAL
|
21 |
+
|
22 |
+
Client Requirement:
|
23 |
+
{client_description}
|
24 |
+
|
25 |
+
Proposed Solution:
|
26 |
+
{generated_only}
|
27 |
+
|
28 |
+
Sincerely,
|
29 |
+
AI Proposal Generator
|
30 |
+
"""
|
31 |
+
|
32 |
+
# Create a PDF
|
33 |
+
pdf = FPDF()
|
34 |
+
pdf.add_page()
|
35 |
+
pdf.set_auto_page_break(auto=True, margin=15)
|
36 |
+
pdf.set_font("Arial", size=12)
|
37 |
+
for line in formatted.split("\n"):
|
38 |
+
pdf.multi_cell(0, 10, line)
|
39 |
+
|
40 |
+
# Save to a temporary file
|
41 |
+
pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf")
|
42 |
+
pdf.output(pdf_file.name)
|
43 |
+
|
44 |
+
# Email suggestion
|
45 |
+
email_body = f"""
|
46 |
+
Subject: Business Proposal for Your Project
|
47 |
+
|
48 |
+
Dear Client,
|
49 |
+
|
50 |
+
Please find attached a professional proposal based on your provided requirements. We're confident this solution meets your needs and are open to feedback or further discussion.
|
51 |
+
|
52 |
+
Best regards,
|
53 |
+
Your Name
|
54 |
+
AI Proposal Generator
|
55 |
+
"""
|
56 |
+
|
57 |
+
return formatted, email_body, pdf_file.name
|
58 |
|
59 |
+
# Gradio UI
|
60 |
iface = gr.Interface(
|
61 |
fn=generate_proposal,
|
62 |
inputs=gr.Textbox(label="Client Requirement", placeholder="Describe the project or client needs here...", lines=5),
|
63 |
+
outputs=[
|
64 |
+
gr.Textbox(label="Formatted Proposal", lines=15),
|
65 |
+
gr.Textbox(label="Email Template", lines=10),
|
66 |
+
gr.File(label="Download Proposal as PDF")
|
67 |
+
],
|
68 |
title="AI Proposal Generator",
|
69 |
+
description="Enter a client request and receive a professional proposal, an email draft, and a downloadable PDF."
|
70 |
)
|
71 |
|
|
|
72 |
iface.launch()
|