BhanuPrakashSamoju commited on
Commit
9d73d29
β€’
1 Parent(s): 1febdeb

Upload 12 files

Browse files
Files changed (3) hide show
  1. Index.py +0 -1
  2. streamapp.py +92 -35
  3. test-logo.png +0 -0
Index.py CHANGED
@@ -66,7 +66,6 @@ handler = StdOutCallbackHandler()
66
  vectorstore = None
67
  retriever = None
68
 
69
- print("Hi There!")
70
 
71
  def initialize_vectorstore():
72
 
 
66
  vectorstore = None
67
  retriever = None
68
 
 
69
 
70
  def initialize_vectorstore():
71
 
streamapp.py CHANGED
@@ -32,18 +32,32 @@ import pandas as pd
32
  # from sklearn import datasets
33
  # from sklearn.ensemble import RandomForestClassifier
34
 
35
- #phoenix setup
36
- session = px.launch_app()
37
- # If no exporter is specified, the tracer will export to the locally running Phoenix server
38
- tracer = OpenInferenceTracer()
39
- # If no tracer is specified, a tracer is constructed for you
40
- LangChainInstrumentor(tracer).instrument()
41
- print(session.url)
42
 
43
 
 
44
 
45
- tab1, tab2, tab3 = st.tabs(["πŸ“ˆ RAG", "πŸ—ƒ FactVsHallucinate" , "trace"])
 
 
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
 
49
 
@@ -151,11 +165,21 @@ def _load_docs(path: str):
151
 
152
 
153
  def rag_response(response):
154
- st.markdown("""<hr style="height:10px;border:none;color:#333;background-color:#333;" /> """, unsafe_allow_html=True)
155
- st.subheader('RAG response')
156
- st.text_area(label="user query", value=response["query"], height=30)
157
- st.text_area(label="RAG output", value=response["result"])
158
- st.text_area(label="Augmented knowledge", value=response["source_documents"])
 
 
 
 
 
 
 
 
 
 
159
 
160
  #st.button("Check Hallucination")
161
 
@@ -177,7 +201,8 @@ def hallu_eval(question: str, answer: str, context: str):
177
  }
178
  )
179
  print("got hallu score")
180
- st.text_area(label="Hallucinated?", value=hallucination_score, height=30)
 
181
  #return {"hallucination_score": hallucination_score}
182
  #time.sleep(10)
183
 
@@ -210,12 +235,32 @@ with tab1:
210
 
211
  #print("lenght in tab1, ", len(vectorstore.serialize_to_bytes()))
212
  options = ["true", "false"]
213
- question = st.text_input(label="***User Question***", value="", label_visibility="visible", disabled=False)
214
- evaluate = st.selectbox(label="***Evaluation***",options=options, index=0, placeholder="Choose an option", disabled=False, label_visibility="visible")
215
-
216
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
 
218
- if st.form_submit_button("RAG with evaluation"):
219
  print("retrie ,", retriever)
220
  chain = RetrievalQA.from_chain_type(
221
  llm=llm,
@@ -255,30 +300,32 @@ with tab2:
255
 
256
 
257
  #print("lenght in tab2, ", len(vectorstore.serialize_to_bytes()))
258
- question = st.text_input(label="question", value="", label_visibility="visible", disabled=False)
259
- answer = st.text_input(label="answer", value="", label_visibility="visible", disabled=False)
260
- context = st.text_input(label="context", value="", label_visibility="visible", disabled=False)
261
 
262
 
263
  if st.form_submit_button("Evaluate"):
264
  hallu_eval(question, answer, context)
265
 
266
-
267
 
268
- with tab3:
 
 
 
 
 
269
 
270
 
271
 
272
- with st.form(" trace"):
273
-
274
- if px.active_session():
275
- df0 = px.active_session().get_spans_dataframe()
276
- if (df0 != None):
277
- if not df0.empty:
278
- df= df0.fillna('')
279
- st.dataframe(df)
280
- else:
281
- print("No Dataframe!")
282
 
283
 
284
 
@@ -340,4 +387,14 @@ def rag():
340
  #st.write("Doing more optional stuff")
341
 
342
 
343
- return(response)
 
 
 
 
 
 
 
 
 
 
 
32
  # from sklearn import datasets
33
  # from sklearn.ensemble import RandomForestClassifier
34
 
35
+ from PIL import Image
 
 
 
 
 
 
36
 
37
 
38
+ global trace_df
39
 
40
+ # Page config
41
+ st.set_page_config(page_title="RAG PoC", layout="wide")
42
+ st.sidebar.image(Image.open("./test-logo.png"), use_column_width=True)
43
 
44
+ @st.cache_resource
45
+ def tracer_config():
46
+ #phoenix setup
47
+ session = px.launch_app()
48
+ # If no exporter is specified, the tracer will export to the locally running Phoenix server
49
+ tracer = OpenInferenceTracer()
50
+ # If no tracer is specified, a tracer is constructed for you
51
+ LangChainInstrumentor(tracer).instrument()
52
+ time.sleep(3)
53
+ print(session.url)
54
+
55
+ tracer_config()
56
+
57
+
58
+
59
+
60
+ tab1, tab2 = st.tabs(["πŸ“ˆ **RAG**", "πŸ—ƒ FactVsHallucinate" ])
61
 
62
 
63
 
 
165
 
166
 
167
  def rag_response(response):
168
+ #st.markdown("""<hr style="height:10px;border:none;color:#333;background-color:#333;" /> """, unsafe_allow_html=True)
169
+
170
+ #st.markdown(".stTextInput > label {font-size:105%; font-weight:bold; color:blue;} ",unsafe_allow_html=True) #for all text-input label sections
171
+
172
+ question_title = '<h1 style="color:#33ff33;font-size:24px;">Question</h1>'
173
+
174
+
175
+
176
+ st.markdown('<h1 style="color:#100170;font-size:48px;text-align:center;">RAG Response</h1>', unsafe_allow_html=True)
177
+ st.markdown('<h1 style="color:#100170;font-size:24px;">Question</h1>', unsafe_allow_html=True)
178
+ st.text_area(label="", value=response["query"], height=30)
179
+ st.markdown('<h1 style="color:#100170;font-size:24px;">RAG Output</h1>', unsafe_allow_html=True)
180
+ st.text_area(label="", value=response["result"])
181
+ st.markdown('<h1 style="color:#100170;font-size:24px;">Augmented knowledge</h1>', unsafe_allow_html=True)
182
+ st.text_area(label="", value=response["source_documents"])
183
 
184
  #st.button("Check Hallucination")
185
 
 
201
  }
202
  )
203
  print("got hallu score")
204
+ st.markdown('<h1 style="color:#100170;font-size:24px;">Hallucinated?</h1>', unsafe_allow_html=True)
205
+ st.text_area(label=" ", value=hallucination_score, height=30)
206
  #return {"hallucination_score": hallucination_score}
207
  #time.sleep(10)
208
 
 
235
 
236
  #print("lenght in tab1, ", len(vectorstore.serialize_to_bytes()))
237
  options = ["true", "false"]
238
+
239
+ st.markdown('<h1 style="color:#100170;font-size:24px;">User Query</h1>', unsafe_allow_html=True)
240
+
241
+ question = st.text_input(label="", value="", placeholder="Type in question",label_visibility="visible", disabled=False)
242
+ #st.markdown('<h2 style="color:#3a0aa6;font-size:24px;">Evaluation</h2>', unsafe_allow_html=True)
243
+ evaluate = st.selectbox(label="***Perform Evaluation?***",options=options, index=1, placeholder="Choose an option", disabled=False, label_visibility="visible")
244
+
245
+ m = st.markdown("""
246
+ <style>
247
+ div.stButton > button:first-child {
248
+ background-color: #100170;
249
+ color:#ffffff;
250
+ }
251
+ div.stButton > button:hover {
252
+ background-color: #00ff00;
253
+ color:#ff0000;
254
+ }
255
+ </style>""", unsafe_allow_html=True)
256
+
257
+ #st.markdown("----", unsafe_allow_html=True)
258
+ columns = st.columns([2,1,2])
259
+
260
+ if columns[1].form_submit_button(" Start RAG "):
261
+
262
+ st.markdown("""<hr style="height:10px;border:none;color:#333;background-color: #100170;" /> """, unsafe_allow_html=True)
263
 
 
264
  print("retrie ,", retriever)
265
  chain = RetrievalQA.from_chain_type(
266
  llm=llm,
 
300
 
301
 
302
  #print("lenght in tab2, ", len(vectorstore.serialize_to_bytes()))
303
+ question = st.text_input(label="**Question**", value="", label_visibility="visible", disabled=False)
304
+ answer = st.text_input(label="**answer**", value="", label_visibility="visible", disabled=False)
305
+ context = st.text_input(label="**context**", value="", label_visibility="visible", disabled=False)
306
 
307
 
308
  if st.form_submit_button("Evaluate"):
309
  hallu_eval(question, answer, context)
310
 
 
311
 
312
+ print("activ session: ", px.active_session().get_spans_dataframe())
313
+ trace_df = px.active_session().get_spans_dataframe()
314
+
315
+ st.session_state['trace_df'] = trace_df
316
+
317
+ # with tab3:
318
 
319
 
320
 
321
+ # with st.form(" trace"):
322
+
323
+ # if px.active_session():
324
+ # df0 = px.active_session().get_spans_dataframe()
325
+ # if not df0.empty:
326
+ # df= df0.fillna('')
327
+ # st.dataframe(df)
328
+
 
 
329
 
330
 
331
 
 
387
  #st.write("Doing more optional stuff")
388
 
389
 
390
+ return(response)
391
+
392
+
393
+ a = st.markdown("""
394
+ <style>
395
+ div.stTextArea > textarea {
396
+ background-color: #0099ff;
397
+ height: 1400px;
398
+ width: 800px;
399
+ }
400
+ </style>""", unsafe_allow_html=True)
test-logo.png ADDED