NexusInstruments commited on
Commit
a094315
·
verified ·
1 Parent(s): 1ebe0b6

Update pages/Example.py

Browse files
Files changed (1) hide show
  1. pages/Example.py +77 -0
pages/Example.py CHANGED
@@ -5,3 +5,80 @@ import sys, os
5
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
6
 
7
  from utils.backend import run_llm
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
6
 
7
  from utils.backend import run_llm
8
+
9
+ st.title("🧪 Example Playground")
10
+ st.write("This page demonstrates Streamlit UI components and integration with Omniscient utils.")
11
+
12
+ # ─── Tabs Example ─────────────────────────────────────────────
13
+ tab1, tab2, tab3 = st.tabs(["💬 Chatbot Demo", "📊 Widgets Demo", "📂 Layout Demo"])
14
+
15
+ # ─── Chatbot Demo ─────────────────────────────────────────────
16
+ with tab1:
17
+ st.subheader("Chatbot (using utils.backend.run_llm)")
18
+
19
+ if "example_chat" not in st.session_state:
20
+ st.session_state.example_chat = []
21
+
22
+ # Display chat history
23
+ for msg in st.session_state.example_chat:
24
+ with st.chat_message(msg["role"]):
25
+ st.markdown(msg["content"])
26
+
27
+ # Chat input
28
+ if prompt := st.chat_input("Talk to the Example Chatbot..."):
29
+ st.session_state.example_chat.append({"role": "user", "content": prompt})
30
+ with st.chat_message("user"):
31
+ st.markdown(prompt)
32
+
33
+ reply = run_llm(prompt)
34
+ with st.chat_message("assistant"):
35
+ st.markdown(reply)
36
+ st.session_state.example_chat.append({"role": "assistant", "content": reply})
37
+
38
+ # ─── Widgets Demo ─────────────────────────────────────────────
39
+ with tab2:
40
+ st.subheader("Streamlit Widgets Showcase")
41
+
42
+ # Text inputs
43
+ name = st.text_input("Enter your name:", "Analyst")
44
+ age = st.slider("Select your age:", 0, 100, 25)
45
+ agree = st.checkbox("I agree to the terms")
46
+
47
+ if st.button("Submit"):
48
+ st.success(f"✅ Submitted: {name}, Age {age}, Agree={agree}")
49
+
50
+ # Metrics
51
+ col1, col2, col3 = st.columns(3)
52
+ col1.metric("Files Uploaded", len(st.session_state.get("uploaded_files", [])))
53
+ col2.metric("Errors Logged", len(st.session_state.get("errors", [])))
54
+ col3.metric("Chat Messages", len(st.session_state.get("messages", [])))
55
+
56
+ # Expander
57
+ with st.expander("See sample code"):
58
+ st.code("st.text_input(), st.slider(), st.checkbox(), st.button()")
59
+
60
+ # ─── Layout Demo ──────────────────────────────────────────────
61
+ with tab3:
62
+ st.subheader("Streamlit Layout Examples")
63
+
64
+ # Columns
65
+ col1, col2 = st.columns([2, 1])
66
+ with col1:
67
+ st.info("This is column 1 (wider)")
68
+ with col2:
69
+ st.warning("This is column 2 (narrower)")
70
+
71
+ # File uploader
72
+ demo_file = st.file_uploader("Upload a file for preview", type=["txt", "log"])
73
+ if demo_file:
74
+ content = demo_file.read().decode("utf-8", errors="ignore")
75
+ st.code("\n".join(content.splitlines()[:20]))
76
+
77
+ # Progress bar demo
78
+ if st.button("Run Progress Demo"):
79
+ import time
80
+ progress = st.progress(0)
81
+ for i in range(100):
82
+ time.sleep(0.02)
83
+ progress.progress(i + 1)
84
+ st.success("Progress complete!")