mibrahimzia commited on
Commit
9393a9f
·
verified ·
1 Parent(s): 571942f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -10
app.py CHANGED
@@ -1,24 +1,72 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
 
 
3
 
4
- # Load the model pipeline
5
  generator = pipeline("text-generation", model="gpt2")
6
 
7
-
8
- # Define the function to generate proposal text
9
  def generate_proposal(client_description):
10
- prompt = f"Generate a professional project proposal based on the following client request:\n\n{client_description}\n\nProposal:"
11
- result = generator(prompt, max_length=512, do_sample=True, temperature=0.7)
12
- return result[0]['generated_text']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- # Build the Gradio interface
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=gr.Textbox(label="Generated Proposal", lines=15),
 
 
 
 
19
  title="AI Proposal Generator",
20
- description="This app uses Mistral-7B to generate business proposals based on client input."
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()