Spaces:
Runtime error
Runtime error
added ngrok
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import requests
|
|
| 3 |
from MathEngine import calculate, CalculationRequest, app as fastapi_app
|
| 4 |
import uvicorn
|
| 5 |
from multiprocessing import Process
|
|
|
|
| 6 |
|
| 7 |
# Gradio Interface
|
| 8 |
history = []
|
|
@@ -31,7 +32,7 @@ def backspace():
|
|
| 31 |
return current_input
|
| 32 |
|
| 33 |
def test_fastapi(a, b, operation):
|
| 34 |
-
url = "
|
| 35 |
payload = {"a": a, "b": b, "operation": operation}
|
| 36 |
headers = {"Content-Type": "application/json"}
|
| 37 |
response = requests.post(url, json=payload, headers=headers)
|
|
@@ -70,15 +71,23 @@ def create_interface():
|
|
| 70 |
|
| 71 |
def run_gradio():
|
| 72 |
demo = create_interface()
|
| 73 |
-
demo.launch(
|
| 74 |
|
| 75 |
def run_fastapi():
|
| 76 |
uvicorn.run(fastapi_app, host="0.0.0.0", port=8000)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
if __name__ == "__main__":
|
| 79 |
p1 = Process(target=run_gradio)
|
| 80 |
p2 = Process(target=run_fastapi)
|
|
|
|
| 81 |
p1.start()
|
| 82 |
p2.start()
|
|
|
|
| 83 |
p1.join()
|
| 84 |
-
p2.join()
|
|
|
|
|
|
| 3 |
from MathEngine import calculate, CalculationRequest, app as fastapi_app
|
| 4 |
import uvicorn
|
| 5 |
from multiprocessing import Process
|
| 6 |
+
from pyngrok import ngrok
|
| 7 |
|
| 8 |
# Gradio Interface
|
| 9 |
history = []
|
|
|
|
| 32 |
return current_input
|
| 33 |
|
| 34 |
def test_fastapi(a, b, operation):
|
| 35 |
+
url = f"{ngrok_tunnel}/calculate"
|
| 36 |
payload = {"a": a, "b": b, "operation": operation}
|
| 37 |
headers = {"Content-Type": "application/json"}
|
| 38 |
response = requests.post(url, json=payload, headers=headers)
|
|
|
|
| 71 |
|
| 72 |
def run_gradio():
|
| 73 |
demo = create_interface()
|
| 74 |
+
demo.launch()
|
| 75 |
|
| 76 |
def run_fastapi():
|
| 77 |
uvicorn.run(fastapi_app, host="0.0.0.0", port=8000)
|
| 78 |
|
| 79 |
+
def run_ngrok():
|
| 80 |
+
global ngrok_tunnel
|
| 81 |
+
ngrok_tunnel = ngrok.connect(8000)
|
| 82 |
+
print(f" * Ngrok tunnel available at: {ngrok_tunnel.public_url}")
|
| 83 |
+
|
| 84 |
if __name__ == "__main__":
|
| 85 |
p1 = Process(target=run_gradio)
|
| 86 |
p2 = Process(target=run_fastapi)
|
| 87 |
+
p3 = Process(target=run_ngrok)
|
| 88 |
p1.start()
|
| 89 |
p2.start()
|
| 90 |
+
p3.start()
|
| 91 |
p1.join()
|
| 92 |
+
p2.join()
|
| 93 |
+
p3.join()
|