Spaces:
Sleeping
Sleeping
| import gradio as gr # type: ignore | |
| # Définition de la fonction calculator | |
| def calculator(num1, num2, operation): | |
| if operation == 'multiply': | |
| return num1 * num2 | |
| elif operation == 'add': | |
| return num1 + num2 | |
| elif operation == 'subtract': | |
| return num1 - num2 | |
| elif operation == 'divide': | |
| if num2 != 0: | |
| return num1 / num2 | |
| else: | |
| return "Division par zéro impossible" | |
| else: | |
| return "Opération non valide" | |
| gr.Blocks(theme=gr.themes.Default(primary_hue=gr.themes.colors.red, secondary_hue=gr.themes.colors.pink)) | |
| # Définition des composants d'entrée et de sortie avec les nouvelles classes | |
| inputs = [ | |
| gr.Number(label="Premier nombre"), | |
| gr.Number(label="Deuxième nombre"), | |
| gr.Radio(label="Opération", choices=["add", "subtract", "multiply", "divide"], value="add" ) | |
| ] | |
| output = gr.Textbox(label="Résultat") | |
| # Création de l'interface Gradio avec les nouvelles classes | |
| interface = gr.Interface(fn=calculator, inputs=inputs, outputs=output, title="Calculatrice", theme=gr.themes.Default(primary_hue=gr.themes.colors.yellow, secondary_hue=gr.themes.colors.neutral)) | |
| # Lancement de l'interface | |
| interface.launch() | |