Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from calculator.operations import perform_calculation
|
| 3 |
+
from calculator.utils import extract_operation, extract_numbers
|
| 4 |
+
|
| 5 |
+
def calculation_interface(question):
|
| 6 |
+
operation = extract_operation(question)
|
| 7 |
+
numbers = extract_numbers(question)
|
| 8 |
+
if not operation or not numbers:
|
| 9 |
+
return "Invalid input! Please provide a valid mathematical question."
|
| 10 |
+
result = perform_calculation(numbers, operation)
|
| 11 |
+
return f"The result of the operation is: {result}"
|
| 12 |
+
|
| 13 |
+
# Gradio interface setup
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=calculation_interface,
|
| 16 |
+
inputs="text",
|
| 17 |
+
outputs="text",
|
| 18 |
+
title="Simple Calculation App",
|
| 19 |
+
description="Provide a mathematical question, and the app will perform the operation."
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
iface.launch()
|