File size: 1,050 Bytes
e5c9ee0
326115c
 
c5fe4a2
e5c9ee0
c5fe4a2
e5c9ee0
acec8bf
326115c
 
 
c5fe4a2
 
3bd20e4
 
c5fe4a2
 
 
 
 
 
 
 
 
3bd20e4
 
c5fe4a2
 
 
 
 
 
3bd20e4
 
c5fe4a2
 
 
 
ca06190
c5fe4a2
 
ca06190
c5fe4a2
f623930
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import gradio as gr
import json
import logging
from fastapi import FastAPI

from utils import session_logger


session_logger.change_logging(logging.DEBUG)


CUSTOM_GRADIO_PATH = "/"
app = FastAPI(title="lisa_app", version="1.0")


@app.get("/health")
@session_logger.set_uuid_logging
def health() -> str:
    try:
        logging.info("health check")
        return json.dumps({"msg": "ok"})
    except Exception as e:
        logging.error(f"exception:{e}.")
        return json.dumps({"msg": "request failed"})


@session_logger.set_uuid_logging
def request_formatter(text: str) -> str:
    logging.info("start request formatting...")
    formatted_text = f"transformed {text}."
    logging.info(f"formatted request as {formatted_text}.")
    return formatted_text


io = gr.Interface(
    request_formatter,
    inputs=[
        gr.Textbox(lines=1, placeholder=None, label="Text input"),
    ],
    outputs=[
        gr.Textbox(lines=1, placeholder=None, label="Text Output"),
    ],
)
app = gr.mount_gradio_app(app, io, path=CUSTOM_GRADIO_PATH)