Commit ·
dfb61f4
1
Parent(s): 648b19a
Add a Gradio-based calculator for the function Y = X² + 3^X + 5 + √X + 2/X
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
def calculate_y(x: float) -> float:
|
| 6 |
+
"""
|
| 7 |
+
数式 Y = X^2 + 3^X + 5 + X^(1/2) + (2/X) を計算します。
|
| 8 |
+
|
| 9 |
+
Args:
|
| 10 |
+
x (float): 正の実数
|
| 11 |
+
|
| 12 |
+
Returns:
|
| 13 |
+
float: 計算結果。x <= 0 の場合はエラーメッセージを返します。
|
| 14 |
+
"""
|
| 15 |
+
if x <= 0:
|
| 16 |
+
return "Error: X must be positive for the square root and division."
|
| 17 |
+
y = x**2 + 3**x + 5 + x**0.5 + (2/x)
|
| 18 |
+
return y
|
| 19 |
+
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
gr.Markdown("# 数式計算ツール")
|
| 22 |
+
with gr.Accordion("Y = X² + 3^X + 5 + √X + 2/X", open=True):
|
| 23 |
+
x_input = gr.Number(label="Xの値(正の実数)", value=1.0)
|
| 24 |
+
y_output = gr.Textbox(label="Yの計算結果", lines=1)
|
| 25 |
+
calc_btn = gr.Button("計算", variant="primary")
|
| 26 |
+
calc_btn.click(fn=calculate_y, inputs=[x_input], outputs=y_output)
|
| 27 |
+
|
| 28 |
+
if __name__ == "__main__":
|
| 29 |
+
demo.launch(mcp_server=True)
|