import gradio as gr import json from PIL import Image import numpy as np # --- User Defined Logic --- import datetime def calendrier(format: str) -> str: """Return the current date formatted according to the requested style. Args: format (str): Desired output format. Accepted values are: - "court": e.g. "25/11/2025" - "long": e.g. "mardi 25 novembre 2025" - "complet": e.g. "mardi 25 novembre 2025 à 14h30" - "iso": e.g. "2025-11-25" - "us": e.g. "11/25/2025" Returns: str: The current date formatted as a string according to the selected format. Raises: ValueError: If an unsupported format string is provided. """ now = datetime.datetime.now() format = format.lower() if format == "court": return now.strftime("%d/%m/%Y") elif format == "iso": return now.strftime("%Y-%m-%d") elif format == "us": return now.strftime("%m/%d/%Y") elif format in ("long", "complet"): weekdays = ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"] months = [ "janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre", ] day_name = weekdays[now.weekday()] month_name = months[now.month - 1] base = f"{day_name} {now.day} {month_name} {now.year}" if format == "complet": return f"{base} à {now.hour:02d}h{now.minute:02d}" return base else: raise ValueError( "Format non supporté. Utilisez 'court', 'long', 'complet', 'iso' ou 'us'." ) # --- Interface Factory --- def create_interface(): return gr.Interface( fn=calendrier, inputs=[gr.Textbox(label=k) for k in ['format']], outputs=gr.Textbox(label="Date formatée selon le paramètre choisi"), title="calendrier", description="Auto-generated tool: calendrier" )