from datasets import load_dataset from datetime import datetime from huggingface_hub import login import os import gradio as gr import pyperclip # show alert function def show_alert(success, message): if success: # gr.Info("") gr.Success(message) else: gr.Error("An error occurred!") # Load the dataset from Hugging Face login(os.getenv('HUGGING_FACE_KEY')) dataset = load_dataset("BrynnSalonga/payment-reminder") df = dataset['train'].to_pandas() # Convert dataset to DataFrame # format date def format_date(date_input): if isinstance(date_input, str): # Convert the string to a datetime object date_obj = datetime.strptime(date_input, "%Y-%m-%d").date() else: return "Invalid date format." # Format the date as "Month Day, Year" formatted_date = date_obj.strftime("%B %d, %Y") return formatted_date # function to generate a reminder and replace placeholders with actual values def generate_reminder(reminder_tone, debtor, invoice_number, amount_due, due_date, currency, creditor): # Filter the dataset based on the selected tone reminder_data = df[df['reminder_tone'] == reminder_tone] if reminder_data.empty: return "❌ Sorry, no reminder found for the selected tone." # Get the corresponding reminder text in the dataset reminder_text = reminder_data.iloc[0]['reminder_text'] # Replace placeholders with actual values reminder_text = reminder_text.replace("[customer_name]", debtor) reminder_text = reminder_text.replace("[invoice_number]", invoice_number) reminder_text = reminder_text.replace("[amount_due]", amount_due) reminder_text = reminder_text.replace("[due_date]", format_date(due_date)) reminder_text = reminder_text.replace("[currency]", currency) reminder_text = reminder_text.replace("[creditor]", creditor) return reminder_text # function for copy to clipboard def copy_to_clipboard(output_text_value): pyperclip.copy(output_text_value) # Copy the value to clipboard show_alert(success=True, message="Copied to clipboard!")