baderanas commited on
Commit
8646d16
·
verified ·
1 Parent(s): 67e19f4

show context

Browse files
Files changed (1) hide show
  1. streamlit.py +85 -11
streamlit.py CHANGED
@@ -9,9 +9,8 @@ logging.basicConfig(level=logging.INFO)
9
  logger = logging.getLogger(__name__)
10
 
11
  # Set page config
12
- st.set_page_config(page_title="Certification Chat", layout="centered")
13
-
14
- st.title("🎓 Certification Chat Assistant")
15
 
16
  # Create a function to handle the async call
17
  async def async_query(query_text):
@@ -29,22 +28,97 @@ def run_async(coroutine):
29
  return loop.run_until_complete(coroutine)
30
 
31
  # User input
32
- user_input = st.text_area("💬 Enter your prompt:", height=150)
33
 
34
  if user_input:
35
- st.markdown("## 🧠 Response")
36
-
37
  try:
38
  # Use try-except to handle errors
39
  with st.spinner("Processing your query..."):
40
  # Run the async function
41
  result = run_async(async_query(user_input))
42
 
43
- # Display output
44
- st.write("**Certification:**", result["certification"])
45
- st.write("**Answer from '.' chunking method:**", result["certif_index"])
46
- st.write("**Answer from hybrid chunking method:**", result["certification_index"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  except Exception as e:
49
  st.error(f"An error occurred: {str(e)}")
50
- logger.error(f"Error processing query: {e}", exc_info=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  logger = logging.getLogger(__name__)
10
 
11
  # Set page config
12
+ st.set_page_config(page_title="Certification Chat", layout="wide")
13
+ st.title("🎓 Hydrogen Certification Chat Assistant")
 
14
 
15
  # Create a function to handle the async call
16
  async def async_query(query_text):
 
28
  return loop.run_until_complete(coroutine)
29
 
30
  # User input
31
+ user_input = st.text_area("💬 Enter your question about hydrogen certification:", height=100)
32
 
33
  if user_input:
 
 
34
  try:
35
  # Use try-except to handle errors
36
  with st.spinner("Processing your query..."):
37
  # Run the async function
38
  result = run_async(async_query(user_input))
39
 
40
+ # Display output in tabs
41
+ st.markdown("## 🧠 Response")
42
+
43
+ # Certification info
44
+ st.subheader(f"Detected Certification: {result['certification']}")
45
+
46
+ # Create tabs for answers and contexts
47
+ tab1, tab2, tab3, tab4 = st.tabs([
48
+ "Answers",
49
+ "Context Details",
50
+ "Raw Context (Dot Chunking)",
51
+ "Raw Context (Hybrid Chunking)"
52
+ ])
53
+
54
+ with tab1:
55
+ st.markdown("### Basic Chunking Answer:")
56
+ st.write(result["certif_index"])
57
+
58
+ st.markdown("### Hybrid Chunking Answer:")
59
+ st.write(result["certification_index"])
60
+
61
+ with tab2:
62
+ col1, col2 = st.columns(2)
63
+
64
+ with col1:
65
+ st.markdown("### Basic Chunking Context Sources:")
66
+ for i, context_item in enumerate(result["context_certif"]):
67
+ with st.expander(f"Source {i+1}"):
68
+ st.write(context_item)
69
+
70
+ with col2:
71
+ st.markdown("### Hybrid Chunking Context Sources:")
72
+ for i, context_item in enumerate(result["context_certifications"]):
73
+ with st.expander(f"Source {i+1}"):
74
+ st.write(context_item)
75
+
76
+ with tab3:
77
+ st.markdown("### Raw Context (Dot Chunking):")
78
+ for i, chunk in enumerate(result["context_certif"]):
79
+ st.text_area(f"Chunk {i+1}", chunk, height=150)
80
+
81
+ with tab4:
82
+ st.markdown("### Raw Context (Hybrid Chunking):")
83
+ for i, chunk in enumerate(result["context_certifications"]):
84
+ st.text_area(f"Chunk {i+1}", chunk, height=150)
85
+
86
+ # Add a section for feedback
87
+ st.markdown("---")
88
+ st.markdown("### Feedback")
89
+ feedback = st.radio(
90
+ "How helpful was this response?",
91
+ ["Very helpful", "Somewhat helpful", "Not helpful"]
92
+ )
93
+ feedback_text = st.text_area("Additional feedback (optional):", height=100)
94
+ if st.button("Submit Feedback"):
95
+ st.success("Thank you for your feedback!")
96
 
97
  except Exception as e:
98
  st.error(f"An error occurred: {str(e)}")
99
+ logger.error(f"Error processing query: {e}", exc_info=True)
100
+ else:
101
+ st.info("👆 Enter your question about hydrogen certifications above to get started!")
102
+
103
+ # Add sidebar with information
104
+ with st.sidebar:
105
+ st.markdown("## About")
106
+ st.markdown("""
107
+ This tool helps answer questions about hydrogen certification standards using
108
+ a Retrieval-Augmented Generation (RAG) system.
109
+
110
+ The system:
111
+ 1. Classifies which certification your question is about
112
+ 2. Optimizes your query
113
+ 3. Retrieves relevant information
114
+ 4. Generates a precise answer
115
+ """)
116
+
117
+ st.markdown("## Available Certifications")
118
+ try:
119
+ from app import list_certifications
120
+ certifications = run_async(list_certifications())
121
+ for cert in certifications:
122
+ st.markdown(f"- {cert}")
123
+ except Exception as e:
124
+ st.warning("Could not load certification list")