import gradio as gr import os from config import STATIONS from supabase_utils import get_supabase_client def create_ui(prediction_handler, chatbot_handler): """Gradio UI를 생성하고 반환합니다.""" with gr.Blocks(title="통합 조위 예측 시스템", theme=gr.themes.Soft()) as demo: gr.Markdown("# 🌊 통합 조위 예측 시스템 with Gemini") # 연결 상태 표시 client = get_supabase_client() supabase_status = "🟢 연결됨" if client else "🔴 연결 안됨 (환경변수 확인 필요)" gemini_status = "🟢 연결됨" if os.getenv("GEMINI_API_KEY") else "🔴 연결 안됨 (환경변수 확인 필요)" gr.Markdown(f"**Supabase 상태**: {supabase_status} | **Gemini 상태**: {gemini_status}") with gr.Tabs(): with gr.TabItem("통합 조위 예측"): with gr.Row(): with gr.Column(scale=1): station_id_input = gr.Dropdown(STATIONS, label="관측소 선택", value="DT_0001") input_csv = gr.File(label="과거 데이터 업로드 (.csv)") predict_btn = gr.Button("예측 실행", variant="primary") with gr.Column(scale=3): output_plot = gr.Plot(label="예측 결과 시각화") output_df = gr.DataFrame(label="예측 결과 데이터") output_log = gr.Textbox(label="실행 로그", lines=5, interactive=False) with gr.TabItem("AI 조위 챗봇"): gr.ChatInterface( fn=chatbot_handler, title="AI 조위 챗봇", description="조위에 대해 궁금한 점을 물어보세요. (예: '인천 오늘 현재 조위 알려줘')", #examples=[] ) predict_btn.click( fn=prediction_handler, inputs=[station_id_input, input_csv], outputs=[output_plot, output_df, output_log] ) return demo