DivyaShah2025's picture
Upload folder using huggingface_hub
e0ce0f6 verified
from pydantic import BaseModel, Field
from agents import Agent
from agents.prompts import Prompt
from pypdf import PdfReader
import PyPDF2
# === 1. Instructions for the model ===
INSTRUCTIONS = (
"You are a Proforma Invoice Generator assistant. "
"Given customer details, produce a clear, structured Proforma Invoice in plain text. "
"Include Consignor (True Vybes, Thane, GSTIN: 27BVOPS7767J2ZF), "
"Consignee section (customer name, address, GSTIN, date), "
"product table with Sl. No., Description, Code, Qty, Rate/unit, Value, "
"total, GST @ 18%, Grand Total, bank details, standard terms, "
"and 'Authorised Signatory' at the end. "
"Output ONLY the invoice content, no extra text."
)
# === 2. Create the prompt ===
def prompt_fn(data):
# same debug:
if hasattr(data, "input"):
user_input = data.input
elif hasattr(data, "raw_input"):
user_input = data.raw_input
elif hasattr(data, "__dict__"):
user_input = data.__dict__
else:
user_input = data # fallback
final_prompt = f"""
Customer Name: {user_input.get('customer_name')}
Address: {user_input.get('address')}
GSTIN: {user_input.get('gst_number')}
Date: {user_input.get('date')}
Product: {user_input.get('product_name')}
Qty: {user_input.get('quantity')}
Price per piece: {user_input.get('price_per_piece')}
"""
return Prompt(content=final_prompt)
class ProformaInvoice(BaseModel):
proforma_invoice: str = Field(description="Final Proforma invoice")
writer_agent = Agent(
name="PI Generator agent",
instructions=INSTRUCTIONS,
prompt=prompt_fn,
model="gpt-4o-mini",
output_type=ProformaInvoice,
)
# === 4. Extract invoice text ===
#invoice_text = response.choices[0].message.content
#print("Generated Invoice:\n")
#print(invoice_text)
# === 5. Save as HTML ===
##html_content = f"<pre>{invoice_text}</pre>"
#with open("invoice.html", "w") as f:
# f.write(html_content)
# === 6. Convert to PDF ===