spagestic's picture
feat: simplify descriptions and examples in Gradio interfaces for arithmetic and calculus tools
db31576
raw
history blame contribute delete
533 Bytes
from typing import Union
import gradio as gr
def divide(a: float, b: float) -> Union[float, str]:
"""Divide a by b."""
try:
a, b = float(a), float(b)
if b == 0:
return "Error: Division by zero"
return a / b
except (ValueError, TypeError):
return "Error: Both inputs must be valid numbers"
divide_interface = gr.Interface(
fn=divide,
inputs=[gr.Number(label="A"), gr.Number(label="B")],
outputs="text",
title="Division",
description="Divide two numbers"
)