Skip to content
Snippets Groups Projects
Commit fc2c0cb6 authored by fima's avatar fima :beers:
Browse files

Merge branch 'fastapi_gradio_mount' into 'main'

Using FastAPI to mount gradio apps

See merge request !33
parents d2fe6508 4c5ba7b3
No related branches found
No related tags found
1 merge request!33Using FastAPI to mount gradio apps
......@@ -354,10 +354,6 @@ class Operations:
if __name__ == "__main__":
# Get port using the QIM API
port_dict = internal_tools.get_port_dict()
internal_tools.gradio_header(Interface().title, port_dict["port"])
# Creates interface
app = Interface().create_interface()
app.launch(server_name="0.0.0.0", server_port=int(port_dict["port"]))
gradio_interface = Interface().create_interface()
internal_tools.run_gradio_app(gradio_interface)
......@@ -476,10 +476,6 @@ class Pipeline:
if __name__ == "__main__":
# Get port using the QIM API
port_dict = internal_tools.get_port_dict()
internal_tools.gradio_header(Interface().title, port_dict["port"])
# Creates interface
app = Interface().create_interface()
app.launch(server_name="0.0.0.0", server_port=int(port_dict["port"]))
gradio_interface = Interface().create_interface()
internal_tools.run_gradio_app(gradio_interface)
......@@ -398,10 +398,6 @@ class Interface:
if __name__ == "__main__":
# Get port using the QIM API
port_dict = internal_tools.get_port_dict()
internal_tools.gradio_header(Interface().title, port_dict["port"])
# Creates interface
app = Interface().create_interface()
app.launch(server_name="0.0.0.0", server_port=int(port_dict["port"]))
gradio_interface = Interface().create_interface()
internal_tools.run_gradio_app(gradio_interface)
......@@ -12,7 +12,6 @@ import plotly.graph_objects as go
import localthickness as lt
import matplotlib
# matplotlib.use("Agg")
import matplotlib.pyplot as plt
......@@ -424,10 +423,6 @@ class Pipeline:
if __name__ == "__main__":
# Get port using the QIM API
port_dict = internal_tools.get_port_dict()
internal_tools.gradio_header(Interface().title, port_dict["port"])
# Creates interface
app = Interface().create_interface()
app.launch(server_name="0.0.0.0", server_port=int(port_dict["port"]))
gradio_interface = Interface().create_interface()
internal_tools.run_gradio_app(gradio_interface)
......@@ -14,7 +14,9 @@ import getpass
from PIL import Image
from pathlib import Path
from qim3d.io.logger import log
from fastapi import FastAPI
import gradio as gr
from uvicorn import run
def mock_plot():
"""Creates a mock plot of a sine wave.
......@@ -265,3 +267,20 @@ def get_port_dict():
raise (f"Error: {response.status_code}")
return port_dict
def run_gradio_app(gradio_interface):
host = "0.0.0.0"
# Get port using the QIM API
port_dict = get_port_dict()
gradio_header(gradio_interface.title, port_dict["port"])
# Create FastAPI with mounted gradio interface
app = FastAPI()
path = f"/gui/{port_dict['username']}/{port_dict['port']}/"
app = gr.mount_gradio_app(app, gradio_interface, path=path)
# Full path
print(f"http://{host}:{port_dict['port']}{path}")
# Run the FastAPI server usign uvicorn
run(app, host="0.0.0.0", port=int(port_dict["port"]))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment