Spaces:
Paused
Paused
alessandro trinca tornidor
commited on
Commit
•
3444a36
1
Parent(s):
0304edb
[feat] add dedicated router
Browse files- app_gradio_fastapi/main.py +14 -10
- app_gradio_fastapi/routes.py +17 -0
app_gradio_fastapi/main.py
CHANGED
@@ -1,19 +1,23 @@
|
|
1 |
from fastapi import FastAPI
|
2 |
import gradio as gr
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
app = FastAPI()
|
7 |
|
8 |
|
9 |
def request_formatter(text: str) -> str:
|
10 |
return f"transformed {text}."
|
11 |
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
import gradio as gr
|
3 |
|
4 |
+
from app_gradio_fastapi import routes
|
|
|
|
|
5 |
|
6 |
|
7 |
def request_formatter(text: str) -> str:
|
8 |
return f"transformed {text}."
|
9 |
|
10 |
|
11 |
+
CUSTOM_GRADIO_PATH = "/"
|
12 |
+
app = FastAPI(title="logging_app", version="1.0")
|
13 |
+
app.include_router(routes.router)
|
14 |
+
io = gr.Interface(
|
15 |
+
request_formatter,
|
16 |
+
inputs=[
|
17 |
+
gr.Textbox(lines=1, placeholder=None, label="Text input"),
|
18 |
+
],
|
19 |
+
outputs=[
|
20 |
+
gr.Textbox(lines=1, placeholder=None, label="Text Output"),
|
21 |
+
],
|
22 |
+
)
|
23 |
+
app = gr.mount_gradio_app(app, io, path=CUSTOM_GRADIO_PATH)
|
app_gradio_fastapi/routes.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import logging
|
3 |
+
|
4 |
+
from fastapi import APIRouter
|
5 |
+
|
6 |
+
|
7 |
+
router = APIRouter()
|
8 |
+
|
9 |
+
|
10 |
+
@router.get("/health")
|
11 |
+
def health():
|
12 |
+
try:
|
13 |
+
logging.info("health check")
|
14 |
+
return json.dumps({"msg": "ok"})
|
15 |
+
except Exception as e:
|
16 |
+
logging.error(f"exception:{e}.")
|
17 |
+
return json.dumps({"msg": "request failed"})
|