|
import gradio as gr |
|
|
|
|
|
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)) |
|
|
|
|
|
|
|
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") |
|
|
|
|
|
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)) |
|
|
|
|
|
interface.launch() |
|
|
|
|
|
|