Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from MathEngine import calculate, CalculationRequest, app as fastapi_app
|
| 3 |
import uvicorn
|
| 4 |
from multiprocessing import Process
|
|
@@ -29,6 +30,13 @@ def backspace():
|
|
| 29 |
current_input = current_input[:-1]
|
| 30 |
return current_input
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
def create_interface():
|
| 33 |
with gr.Blocks() as demo:
|
| 34 |
a = gr.Number(label="A", interactive=True)
|
|
@@ -52,11 +60,17 @@ def create_interface():
|
|
| 52 |
gr.Button("Multiply").click(lambda a, b: gradio_calculate(a, b, "multiply"), inputs=[a, b], outputs=result)
|
| 53 |
gr.Button("Divide").click(lambda a, b: gradio_calculate(a, b, "divide"), inputs=[a, b], outputs=result)
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
return demo
|
| 56 |
|
| 57 |
def run_gradio():
|
| 58 |
demo = create_interface()
|
| 59 |
-
demo.launch(share=True)
|
| 60 |
|
| 61 |
def run_fastapi():
|
| 62 |
uvicorn.run(fastapi_app, host="0.0.0.0", port=8000)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
from MathEngine import calculate, CalculationRequest, app as fastapi_app
|
| 4 |
import uvicorn
|
| 5 |
from multiprocessing import Process
|
|
|
|
| 30 |
current_input = current_input[:-1]
|
| 31 |
return current_input
|
| 32 |
|
| 33 |
+
def test_fastapi(a, b, operation):
|
| 34 |
+
url = "http://0.0.0.0:8000/calculate"
|
| 35 |
+
payload = {"a": a, "b": b, "operation": operation}
|
| 36 |
+
headers = {"Content-Type": "application/json"}
|
| 37 |
+
response = requests.post(url, json=payload, headers=headers)
|
| 38 |
+
return response.json()
|
| 39 |
+
|
| 40 |
def create_interface():
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
a = gr.Number(label="A", interactive=True)
|
|
|
|
| 60 |
gr.Button("Multiply").click(lambda a, b: gradio_calculate(a, b, "multiply"), inputs=[a, b], outputs=result)
|
| 61 |
gr.Button("Divide").click(lambda a, b: gradio_calculate(a, b, "divide"), inputs=[a, b], outputs=result)
|
| 62 |
|
| 63 |
+
with gr.Row():
|
| 64 |
+
gr.Button("Test FastAPI Add").click(lambda a, b: test_fastapi(a, b, "add"), inputs=[a, b], outputs=result)
|
| 65 |
+
gr.Button("Test FastAPI Subtract").click(lambda a, b: test_fastapi(a, b, "subtract"), inputs=[a, b], outputs=result)
|
| 66 |
+
gr.Button("Test FastAPI Multiply").click(lambda a, b: test_fastapi(a, b, "multiply"), inputs=[a, b], outputs=result)
|
| 67 |
+
gr.Button("Test FastAPI Divide").click(lambda a, b: test_fastapi(a, b, "divide"), inputs=[a, b], outputs=result)
|
| 68 |
+
|
| 69 |
return demo
|
| 70 |
|
| 71 |
def run_gradio():
|
| 72 |
demo = create_interface()
|
| 73 |
+
demo.launch(share=True) # Ensure share=True to make the Gradio interface publicly accessible
|
| 74 |
|
| 75 |
def run_fastapi():
|
| 76 |
uvicorn.run(fastapi_app, host="0.0.0.0", port=8000)
|