Spaces:
Runtime error
Runtime error
| 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!") | |