Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,22 @@
|
|
| 1 |
-
|
| 2 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
b: float
|
| 9 |
-
operation: str
|
| 10 |
-
|
| 11 |
-
@app.post("/calculate")
|
| 12 |
-
def calculate(request: CalculationRequest):
|
| 13 |
-
a = request.a
|
| 14 |
-
b = request.b
|
| 15 |
-
operation = request.operation.lower()
|
| 16 |
-
|
| 17 |
-
if operation == "add":
|
| 18 |
-
result = a + b
|
| 19 |
-
elif operation == "subtract":
|
| 20 |
-
result = a - b
|
| 21 |
-
elif operation == "multiply":
|
| 22 |
-
result = a * b
|
| 23 |
-
elif operation == "divide":
|
| 24 |
-
if b == 0:
|
| 25 |
-
raise HTTPException(status_code=400, detail="Division by zero is not allowed")
|
| 26 |
-
result = a / b
|
| 27 |
-
else:
|
| 28 |
-
raise HTTPException(status_code=400, detail="Invalid operation")
|
| 29 |
-
|
| 30 |
-
return {"result": result}
|
| 31 |
-
|
| 32 |
-
# To run the application, use the command: uvicorn app.main:app --reload
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from MathEngine import calculate, CalculationRequest
|
| 3 |
+
# Gradio Interface
|
| 4 |
+
def gradio_calculate(a, b, operation):
|
| 5 |
+
request = CalculationRequest(a=a, b=b, operation=operation)
|
| 6 |
+
response = calculate(request)
|
| 7 |
+
return response["result"]
|
| 8 |
|
| 9 |
+
iface = gr.Interface(
|
| 10 |
+
fn=gradio_calculate,
|
| 11 |
+
inputs=[
|
| 12 |
+
gr.Number(label="A"),
|
| 13 |
+
gr.Number(label="B"),
|
| 14 |
+
gr.Textbox(label="Operation")
|
| 15 |
+
],
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="Calculator",
|
| 18 |
+
description="A simple calculator using FastAPI and Gradio"
|
| 19 |
+
)
|
| 20 |
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|