import streamlit as st
import requests

st.title("Permenpar-AI (Streamlit demo)")
q = st.text_input("Masukkan pertanyaan")
use_llm = st.checkbox("Gunakan LLM (OpenAI)")
if st.button("Tanya"):
    payload = {"question": q, "top_k":5, "use_llm": use_llm}
    res = requests.post("http://127.0.0.1:5000/query", json=payload)
    if res.ok:
        data = res.json()
        if data.get("answer"):
            st.subheader("Jawaban (LLM)")
            st.write(data["answer"])
        st.subheader("Paragraf relevan")
        for h in data["hits"]:
            st.write(h["text"])
    else:
        st.error("API error: " + res.text)
