OpenSLU / app.py
LightChen2333's picture
Upload 34 files
37b9e99
raw
history blame
1.58 kB
import gradio as gr
import os
from common.config import Config
from common.model_manager import ModelManager
config = Config.load_from_yaml("config/app.yaml")
model_manager = ModelManager(config)
model_manager.load()
def text_analysis(text):
print(text)
data = model_manager.predict(text)
html = """<link href="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.staticfile.org/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script>"""
html += """<div style="background: white; padding: 16px;"><b>Intent:</b>"""
for intent in data["intent"]:
html += """<button type="button" class="btn btn-white">
<span class="badge text-dark btn-light">""" + intent + """</span> </button>"""
html += """<br /> <b>Slot:</b>"""
for t, slot in zip(data["text"], data["slot"]):
html += """<button type="button" class="btn btn-white">"""+t+"""<span class="badge text-dark" style="background-color: rgb(255, 255, 255);
color: rgb(62 62 62);
box-shadow: 2px 2px 7px 1px rgba(210, 210, 210, 0.42);">"""+slot+\
"""</span>
</button>"""
html+="</div>"
return html
demo = gr.Interface(
text_analysis,
gr.Textbox(placeholder="Enter sentence here..."),
["html"],
examples=[
["What a beautiful morning for a walk!"],
["It was the best of times, it was the worst of times."],
],
)
demo.launch()