JNU-TSB / app.py
HONGRIZON's picture
Upload 18 files
cf02581 verified
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
import gradio as gr
import pandas as pd
from runtime import JNUTSBRuntime
runtime = JNUTSBRuntime.from_config_dir(Path(__file__).parent)
DEFAULT_STOCK = """timestamp,target
2024-12-01,71000
2024-12-02,71800
2024-12-03,70400
2024-12-04,70900
2024-12-05,72100
"""
DEFAULT_NEWS = """[
{"date": "2024-12-01", "title": "์‚ผ์„ฑ์ „์ž HBM ์‹ ์ œํ’ˆ ์ถœ์‹œ"},
{"date": "2024-12-02", "title": "๋ฐ˜๋„์ฒด ์—…ํ™ฉ ๋‘”ํ™” ์šฐ๋ ค"}
]"""
def run_demo(stock_csv: str, news_json: str, prediction_length: int, use_llm_extractor: bool) -> Any:
from io import StringIO
stock = pd.read_csv(StringIO(stock_csv)) if stock_csv.strip() else None
news = json.loads(news_json) if news_json.strip() else None
result = runtime.predict(
inputs={"stock": stock, "news": news},
prediction_length=int(prediction_length),
use_llm_extractor=bool(use_llm_extractor),
)
return result
with gr.Blocks(title="JNU-TSB") as demo:
gr.Markdown("# JNU-TSB: ํ•œ๊ตญ์–ด ๋‰ด์Šค ๊ธฐ๋ฐ˜ Time-Series Bridge")
gr.Markdown(
"Chronos-2 + Polyglot-Ko + 3-way router ๊ตฌ์กฐ์˜ ๊ต์œก/์—ฐ๊ตฌ์šฉ ๋ฐ๋ชจ์ž…๋‹ˆ๋‹ค. "
"์˜ˆ์ธก ๊ฒฐ๊ณผ๋Š” ํˆฌ์ž ์กฐ์–ธ์ด ์•„๋‹™๋‹ˆ๋‹ค."
)
with gr.Row():
stock_box = gr.Textbox(label="์ฃผ๊ฐ€ CSV", value=DEFAULT_STOCK, lines=9)
news_box = gr.Textbox(label="๋‰ด์Šค JSON", value=DEFAULT_NEWS, lines=9)
with gr.Row():
pred_len = gr.Slider(label="์˜ˆ์ธก ๊ธธ์ด prediction_length", minimum=1, maximum=30, value=3, step=1)
use_llm = gr.Checkbox(label="Polyglot-Ko ์ถ”์ถœ๊ธฐ ์‚ฌ์šฉ", value=False)
btn = gr.Button("JNU-TSB ์‹คํ–‰")
out = gr.JSON(label="๊ฒฐ๊ณผ")
btn.click(run_demo, inputs=[stock_box, news_box, pred_len, use_llm], outputs=out)
if __name__ == "__main__":
demo.launch()