File size: 3,589 Bytes
74d4219
 
 
 
 
 
 
 
0e29175
 
 
 
 
 
 
a094315
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sys, os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
UTILS_DIR = os.path.join(BASE_DIR, "utils")

if UTILS_DIR not in sys.path:
    sys.path.insert(0, UTILS_DIR)

import streamlit as st
import sys, os

# ─── Ensure utils/ is importable ──────────────────────────────
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from utils.backend import run_llm

st.title("🧪 Example Playground")
st.write("This page demonstrates Streamlit UI components and integration with Omniscient utils.")

# ─── Tabs Example ─────────────────────────────────────────────
tab1, tab2, tab3 = st.tabs(["💬 Chatbot Demo", "📊 Widgets Demo", "📂 Layout Demo"])

# ─── Chatbot Demo ─────────────────────────────────────────────
with tab1:
    st.subheader("Chatbot (using utils.backend.run_llm)")
    
    if "example_chat" not in st.session_state:
        st.session_state.example_chat = []

    # Display chat history
    for msg in st.session_state.example_chat:
        with st.chat_message(msg["role"]):
            st.markdown(msg["content"])

    # Chat input
    if prompt := st.chat_input("Talk to the Example Chatbot..."):
        st.session_state.example_chat.append({"role": "user", "content": prompt})
        with st.chat_message("user"):
            st.markdown(prompt)

        reply = run_llm(prompt)
        with st.chat_message("assistant"):
            st.markdown(reply)
        st.session_state.example_chat.append({"role": "assistant", "content": reply})

# ─── Widgets Demo ─────────────────────────────────────────────
with tab2:
    st.subheader("Streamlit Widgets Showcase")

    # Text inputs
    name = st.text_input("Enter your name:", "Analyst")
    age = st.slider("Select your age:", 0, 100, 25)
    agree = st.checkbox("I agree to the terms")

    if st.button("Submit"):
        st.success(f"✅ Submitted: {name}, Age {age}, Agree={agree}")

    # Metrics
    col1, col2, col3 = st.columns(3)
    col1.metric("Files Uploaded", len(st.session_state.get("uploaded_files", [])))
    col2.metric("Errors Logged", len(st.session_state.get("errors", [])))
    col3.metric("Chat Messages", len(st.session_state.get("messages", [])))

    # Expander
    with st.expander("See sample code"):
        st.code("st.text_input(), st.slider(), st.checkbox(), st.button()")

# ─── Layout Demo ──────────────────────────────────────────────
with tab3:
    st.subheader("Streamlit Layout Examples")

    # Columns
    col1, col2 = st.columns([2, 1])
    with col1:
        st.info("This is column 1 (wider)")
    with col2:
        st.warning("This is column 2 (narrower)")

    # File uploader
    demo_file = st.file_uploader("Upload a file for preview", type=["txt", "log"])
    if demo_file:
        content = demo_file.read().decode("utf-8", errors="ignore")
        st.code("\n".join(content.splitlines()[:20]))

    # Progress bar demo
    if st.button("Run Progress Demo"):
        import time
        progress = st.progress(0)
        for i in range(100):
            time.sleep(0.02)
            progress.progress(i + 1)
        st.success("Progress complete!")