Spaces:
Running
Running
import gradio as gr | |
from inference import run_inference | |
from webtest_prompt import build_webtest_prompt | |
# Web Test UI ํธ์ถ ํจ์ | |
def gradio_infer(npc_id, npc_location, player_utt): | |
prompt = build_webtest_prompt(npc_id, npc_location, player_utt) | |
result = run_inference(prompt) | |
return result["npc_output_text"], result["deltas"], result["flags_prob"] | |
# ping: ์ํ ํ์ธ ๋ฐ ๊นจ์ฐ๊ธฐ | |
def ping(): | |
# ๋ชจ๋ธ์ด ๋ก๋๋์ด ์๋์ง ํ์ธ, ์์ผ๋ฉด ๋ก๋ | |
global wrapper, tokenizer, model, flags_order | |
if 'model' not in globals() or model is None: | |
from model_loader import ModelWrapper | |
wrapper = ModelWrapper() | |
tokenizer, model, flags_order = wrapper.get() | |
return {"status": "awake"} | |
with gr.Blocks() as demo: | |
gr.Markdown("## NPC Main Model Inference") | |
with gr.Tab("Web Test UI"): | |
npc_id = gr.Textbox(label="NPC ID") | |
npc_loc = gr.Textbox(label="NPC Location") | |
player_utt = gr.Textbox(label="Player Utterance") | |
npc_resp = gr.Textbox(label="NPC Response") | |
deltas = gr.JSON(label="Deltas") | |
flags = gr.JSON(label="Flags Probabilities") | |
btn = gr.Button("Run Inference") | |
# Web Test ์ ์ฉ (api_name ์ ๊ฑฐ) | |
btn.click( | |
fn=gradio_infer, | |
inputs=[npc_id, npc_loc, player_utt], | |
outputs=[npc_resp, deltas, flags] | |
) | |
# ping ์๋ํฌ์ธํธ (์ํ ํ์ธ/๊นจ์ฐ๊ธฐ) | |
gr.Button("Ping Server").click( | |
fn=ping, | |
inputs=[], | |
outputs=[], | |
api_name="ping" | |
) | |
if __name__ == "__main__": | |
demo.launch(server_name="0.0.0.0", server_port=7860) | |