Spaces:
Running
Running
XQ commited on
Commit ·
672cdab
1
Parent(s): 9d4faef
Add random questions
Browse files- src/ui/app.py +45 -8
src/ui/app.py
CHANGED
|
@@ -5,12 +5,31 @@ Single-page document search interface with clean sans-serif design.
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
import os
|
|
|
|
| 8 |
|
| 9 |
import streamlit as st
|
| 10 |
import requests
|
| 11 |
|
| 12 |
API_BASE = os.environ.get("API_BASE_URL", "http://localhost:8000")
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# ---------------------------------------------------------------------------
|
| 15 |
# Internationalisation — all UI strings live here
|
| 16 |
# ---------------------------------------------------------------------------
|
|
@@ -48,8 +67,9 @@ TEXTS: dict[str, dict[str, str]] = {
|
|
| 48 |
),
|
| 49 |
"search_label": "Stil et sporgsmål om ... ",
|
| 50 |
"search_placeholder": "F.eks.: Hvad er reglerne for behandling af personoplysninger?",
|
| 51 |
-
"search_button": "
|
| 52 |
-
"
|
|
|
|
| 53 |
"confidence_label": "Konfidensgrad",
|
| 54 |
"intent_label": "Intent",
|
| 55 |
"strategy_label": "Strategi",
|
|
@@ -119,6 +139,7 @@ TEXTS: dict[str, dict[str, str]] = {
|
|
| 119 |
"search_label": "Ask a question ...",
|
| 120 |
"search_placeholder": "E.g.: What are the rules for processing personal data?",
|
| 121 |
"search_button": "Search",
|
|
|
|
| 122 |
"spinner": "Searching documents ...",
|
| 123 |
"confidence_label": "Confidence",
|
| 124 |
"intent_label": "Intent",
|
|
@@ -396,12 +417,28 @@ st.markdown(
|
|
| 396 |
# ---------------------------------------------------------------------------
|
| 397 |
# Search form
|
| 398 |
# ---------------------------------------------------------------------------
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 405 |
|
| 406 |
# ---------------------------------------------------------------------------
|
| 407 |
# Query logic
|
|
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
import os
|
| 8 |
+
import random
|
| 9 |
|
| 10 |
import streamlit as st
|
| 11 |
import requests
|
| 12 |
|
| 13 |
API_BASE = os.environ.get("API_BASE_URL", "http://localhost:8000")
|
| 14 |
|
| 15 |
+
# ---------------------------------------------------------------------------
|
| 16 |
+
# Example questions — drawn from the documents in docs/
|
| 17 |
+
# ---------------------------------------------------------------------------
|
| 18 |
+
EXAMPLE_QUESTIONS: list[str] = [
|
| 19 |
+
"Hvad er reglerne for brug af generativ AI til eksamen på KU?",
|
| 20 |
+
"Hvordan håndteres uansøgt afsked begrundet i institutionens forhold?",
|
| 21 |
+
"Hvad er de disciplinære foranstaltninger over for studerende?",
|
| 22 |
+
"Hvordan skal klager over medarbejdere og ledere behandles?",
|
| 23 |
+
"Hvad er retningslinjerne for afholdelse af MUS-samtaler?",
|
| 24 |
+
"Hvordan er års- og skemastrukturen organiseret på KU?",
|
| 25 |
+
"Hvilke regler gælder for eksamenstilmelding og afmelding?",
|
| 26 |
+
"Hvordan skal studerende dokumentere brug af GAI i skriftlige opgaver?",
|
| 27 |
+
"Hvad er kommunernes ansvar ved brug af generativ AI?",
|
| 28 |
+
"Hvilke principper gælder for akademisk integritet ved brug af AI?",
|
| 29 |
+
"Hvornår kan en leder afvise en klage som åbenbart grundløs?",
|
| 30 |
+
"Hvad er reglerne for forlænget tid til eksamen?",
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
# ---------------------------------------------------------------------------
|
| 34 |
# Internationalisation — all UI strings live here
|
| 35 |
# ---------------------------------------------------------------------------
|
|
|
|
| 67 |
),
|
| 68 |
"search_label": "Stil et sporgsmål om ... ",
|
| 69 |
"search_placeholder": "F.eks.: Hvad er reglerne for behandling af personoplysninger?",
|
| 70 |
+
"search_button": "Søg",
|
| 71 |
+
"example_button": "Tilfaeldigt eksempel",
|
| 72 |
+
"spinner": "Søger i dokumenterne ...",
|
| 73 |
"confidence_label": "Konfidensgrad",
|
| 74 |
"intent_label": "Intent",
|
| 75 |
"strategy_label": "Strategi",
|
|
|
|
| 139 |
"search_label": "Ask a question ...",
|
| 140 |
"search_placeholder": "E.g.: What are the rules for processing personal data?",
|
| 141 |
"search_button": "Search",
|
| 142 |
+
"example_button": "Random example",
|
| 143 |
"spinner": "Searching documents ...",
|
| 144 |
"confidence_label": "Confidence",
|
| 145 |
"intent_label": "Intent",
|
|
|
|
| 417 |
# ---------------------------------------------------------------------------
|
| 418 |
# Search form
|
| 419 |
# ---------------------------------------------------------------------------
|
| 420 |
+
if "example_question" not in st.session_state:
|
| 421 |
+
st.session_state.example_question = ""
|
| 422 |
+
|
| 423 |
+
def _pick_example() -> None:
|
| 424 |
+
"""Select a random example question and store it in session state."""
|
| 425 |
+
st.session_state.example_question = random.choice(EXAMPLE_QUESTIONS)
|
| 426 |
+
|
| 427 |
+
question = st.text_input(
|
| 428 |
+
t["search_label"],
|
| 429 |
+
value=st.session_state.example_question,
|
| 430 |
+
placeholder=t["search_placeholder"],
|
| 431 |
+
)
|
| 432 |
+
|
| 433 |
+
col_search, col_example = st.columns([1, 1])
|
| 434 |
+
with col_search:
|
| 435 |
+
search_clicked = st.button(t["search_button"], use_container_width=True)
|
| 436 |
+
with col_example:
|
| 437 |
+
st.button(t["example_button"], on_click=_pick_example, use_container_width=True)
|
| 438 |
+
|
| 439 |
+
# Clear the stored example so it doesn't persist across manual edits
|
| 440 |
+
if st.session_state.example_question:
|
| 441 |
+
st.session_state.example_question = ""
|
| 442 |
|
| 443 |
# ---------------------------------------------------------------------------
|
| 444 |
# Query logic
|