Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from functions import generate_reminder, copy_to_clipboard | |
| # for copy to clipboard state | |
| def toggle_clipboard_state(output_text_value): | |
| return gr.update(interactive=bool(output_text_value)) | |
| # UI | |
| with gr.Blocks() as main: | |
| gr.Markdown("# Payment Reminder Generator") # Main header | |
| with gr.Row(): # Horizontal layout | |
| with gr.Column(): # Left column | |
| gr.Markdown("### Invoice Details") | |
| creditor_name = gr.Textbox(label="Creditor Name", placeholder="Person name or company who lends money") | |
| debtor_name = gr.Textbox(label="Debtor Name", placeholder="Person name or company who borrows money") | |
| invoice_number = gr.Textbox(label="Invoice no.", placeholder="ex. INV-0001") | |
| with gr.Row(): | |
| amount_due = gr.Textbox(label="Amount Due", placeholder="100", scale=1) | |
| currency = gr.Dropdown(["USD", "AUD", "PHP"], label="Currency", interactive=True, scale=1) | |
| due_date = gr.DateTime(label="Due Date", interactive=True, include_time=False, min_width=130, scale=2, type="string") | |
| tone = gr.Dropdown(["Friendly", "Firm", "Urgent"], label="Select your tone", interactive=True) | |
| generate_btn = gr.Button("Generate", variant="primary") | |
| with gr.Column(): # Right column | |
| gr.Markdown("### Generated Output") | |
| output_text = gr.Textbox(label="Your reminder will appear here.", interactive=False) | |
| copy_btn = gr.Button("Copy to clipboard", variant="secondary", interactive=False) | |
| # if the output_text value changed, this will update the clipboard state | |
| output_text.change(toggle_clipboard_state, inputs=output_text, outputs=copy_btn) | |
| # Connect button to function | |
| generate_btn.click(generate_reminder, inputs=[tone, debtor_name, invoice_number, amount_due, due_date, currency, creditor_name], outputs=output_text) | |
| copy_btn.click(copy_to_clipboard, inputs=output_text) | |
| main.launch() |