| | import gradio as gr |
| | import urllib.parse |
| | from datetime import datetime |
| |
|
| | def send_whatsapp(phone, template, custom_message): |
| | message = custom_message if template == "Custom Message" else templates[template] |
| | if not phone or not message: |
| | return "Please fill in all fields" |
| | |
| | |
| | phone = phone.replace("+", "").replace(" ", "") |
| | |
| | |
| | encoded_message = urllib.parse.quote(message) |
| | whatsapp_link = f"https://wa.me/{phone}?text={encoded_message}" |
| | |
| | return f"Click to send: {whatsapp_link}" |
| |
|
| | templates = { |
| | "Delivery Info": "We offer free delivery within 3-5 business days.", |
| | "Return Policy": "You can return items within 30 days of purchase.", |
| | "Payment Options": "We accept credit cards, PayPal, and bank transfers." |
| | } |
| |
|
| | with gr.Blocks() as app: |
| | gr.Markdown("# WhatsApp Message Sender 💬") |
| | with gr.Row(): |
| | phone = gr.Textbox(label="+923357353615", placeholder="919876543210") |
| | template = gr.Dropdown( |
| | choices=["Custom Message"] + list(templates.keys()), |
| | label="Message Template", |
| | value="Custom Message" |
| | ) |
| | message = gr.Textbox(label="Message", lines=3) |
| | submit = gr.Button("Generate WhatsApp Link") |
| | output = gr.Textbox(label="Result") |
| | |
| | submit.click( |
| | send_whatsapp, |
| | inputs=[phone, template, message], |
| | outputs=output |
| | ) |
| | template.change( |
| | lambda x: templates.get(x, ""), |
| | inputs=template, |
| | outputs=message |
| | ) |
| |
|
| | app.launch() |