''' from transformers import pipeline import gradio as gr generator = pipeline("text-generation", model="sshleifer/tiny-gpt2") def generate_proposal(client_description): generated = generator(client_description, max_length=100, do_sample=True, temperature=0.7) return generated[0]["generated_text"] iface = gr.Interface( fn=generate_proposal, inputs=gr.Textbox(label="Client Requirement"), outputs=gr.Textbox(label="Generated Proposal"), title="Fast Proposal Generator", description="Lightweight and fast text generator using TinyGPT2" ) iface.launch() ''' #______________________________________________________________________________________________________________________________________ import gradio as gr from transformers import pipeline from fpdf import FPDF import tempfile import os # Load the text-generation pipeline using GPT-2 generator = pipeline("text-generation", model="gpt2") # Format the output as a business-style proposal def generate_proposal(client_description): # Generate raw text raw = generator(f"{client_description}", max_length=300, do_sample=True, temperature=0.7)[0]['generated_text'] # Extract only the generated part (remove the prompt from output) generated_only = raw.replace(client_description, "").strip() # Build formatted text formatted = f""" PROJECT PROPOSAL Client Requirement: {client_description} Proposed Solution: {generated_only} Sincerely, AI Proposal Generator """ # Create a PDF pdf = FPDF() pdf.add_page() pdf.set_auto_page_break(auto=True, margin=15) pdf.set_font("Arial", size=12) for line in formatted.split("\n"): pdf.multi_cell(0, 10, line) # Save to a temporary file pdf_file = tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") pdf.output(pdf_file.name) # Email suggestion email_body = f""" Subject: Business Proposal for Your Project Dear Client, 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. Best regards, Your Name AI Proposal Generator """ return formatted, email_body, pdf_file.name # Gradio UI iface = gr.Interface( fn=generate_proposal, inputs=gr.Textbox(label="Client Requirement", placeholder="Describe the project or client needs here...", lines=5), outputs=[ gr.Textbox(label="Formatted Proposal", lines=15), gr.Textbox(label="Email Template", lines=10), gr.File(label="Download Proposal as PDF") ], title="AI Proposal Generator", description="Enter a client request and receive a professional proposal, an email draft, and a downloadable PDF." ) iface.launch()