Carlosito16 commited on
Commit
e221fec
1 Parent(s): 992801a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -8
app.py CHANGED
@@ -1,6 +1,10 @@
1
  import streamlit as st
 
 
 
2
  import pickle
3
  import os
 
4
  import torch
5
  from tqdm.auto import tqdm
6
  from langchain.text_splitter import RecursiveCharacterTextSplitter
@@ -26,7 +30,7 @@ st.markdown("# Hello")
26
 
27
  @st.cache_data
28
  def load_scraped_web_info():
29
- with open("ait-web-document", "rb") as fp:
30
  ait_web_documents = pickle.load(fp)
31
 
32
 
@@ -46,7 +50,6 @@ def load_scraped_web_info():
46
 
47
 
48
 
49
-
50
  @st.cache_resource
51
  def load_embedding_model():
52
  embedding_model = HuggingFaceInstructEmbeddings(model_name='hkunlp/instructor-base',
@@ -87,6 +90,14 @@ def load_retriever(llm, db):
87
  #--------------
88
 
89
 
 
 
 
 
 
 
 
 
90
 
91
  load_scraped_web_info()
92
  embedding_model = load_embedding_model()
@@ -107,20 +118,56 @@ def retrieve_document(query_input):
107
  return related_doc
108
 
109
  def retrieve_answer(query_input):
 
110
  answer = qa_retriever.run(query_input)
 
 
 
 
 
 
111
  return answer
 
 
 
 
 
 
 
 
 
 
112
 
113
- output_1 = st.text_area(label = "Here is the relevant documents",
114
- value = retrieve_document(query_input))
115
 
116
 
117
- output_2 = st.text_area(label = "Here is the answer",
118
- value = retrieve_answer(query_input))
119
 
 
 
 
 
 
 
120
 
 
121
 
122
- # faiss_retriever = vector_database.as_retriever()
123
- # print("Succesfully had FAISS as retriever")s
124
 
125
 
 
 
 
 
 
 
 
 
126
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import datetime
5
  import pickle
6
  import os
7
+ import csv
8
  import torch
9
  from tqdm.auto import tqdm
10
  from langchain.text_splitter import RecursiveCharacterTextSplitter
 
30
 
31
  @st.cache_data
32
  def load_scraped_web_info():
33
+ with open("/Users/carlosito/Library/CloudStorage/OneDrive-Personal/AIT material/99-AIT-thesis/aitGPT/ait-web-document", "rb") as fp:
34
  ait_web_documents = pickle.load(fp)
35
 
36
 
 
50
 
51
 
52
 
 
53
  @st.cache_resource
54
  def load_embedding_model():
55
  embedding_model = HuggingFaceInstructEmbeddings(model_name='hkunlp/instructor-base',
 
90
  #--------------
91
 
92
 
93
+ if "history" not in st.session_state:
94
+ st.session_state.history = []
95
+ if "session_rating" not in st.session_state:
96
+ st.session_state.session_rating = 0
97
+
98
+ def update_score():
99
+ st.session_state.session_rating = st.session_state.rating
100
+
101
 
102
  load_scraped_web_info()
103
  embedding_model = load_embedding_model()
 
118
  return related_doc
119
 
120
  def retrieve_answer(query_input):
121
+
122
  answer = qa_retriever.run(query_input)
123
+ output = st.text_area(label="Retrieved documents", value=answer)
124
+
125
+ st.markdown('---')
126
+ score = st.radio(label = 'please select the overall satifaction and helpfullness of the bot answer', options=[1,2,3,4,5], horizontal=True,
127
+ on_change=update_score, key='rating')
128
+
129
  return answer
130
+
131
+
132
+
133
+
134
+ st.write("# aitGPT 🤖 ")
135
+ st.markdown("""
136
+ #### The aitGPT project is a virtual assistant developed by the :green[Asian Institute of Technology] that contains a vast amount of information gathered from 205 AIT-related websites.
137
+ The goal of this chatbot is to provide an alternative way for applicants and current students to access information about the institute, including admission procedures, campus facilities, and more.
138
+ """)
139
+ st.write(' ⚠️ Please expect to wait **~ 10 - 20 seconds per question** as thi app is running on CPU against 3-billion-parameter LLM')
140
 
141
+ st.markdown("---")
 
142
 
143
 
144
+ query_input = st.text_area(label= 'What would you like to know about AIT?')
145
+ generate_button = st.button(label = 'Submit!')
146
 
147
+ if generate_button:
148
+ answer = retrieve_answer(query_input)
149
+ log = {"timestamp": datetime.datetime.now(),
150
+ "question":query_input,
151
+ "generated_answer": answer,
152
+ "rating":st.session_state.session_rating }
153
 
154
+ st.session_state.history.append(log)
155
 
 
 
156
 
157
 
158
+ if st.session_state.session_rating == 0:
159
+ pass
160
+ else:
161
+ with open('test_db', 'a') as csvfile:
162
+ writer = csv.writer(csvfile)
163
+ writer.writerow([st.session_state.history[-1]['timestamp'], st.session_state.history[-1]['question'],
164
+ st.session_state.history[-1]['generated_answer'], st.session_state.session_rating ])
165
+ st.session_state.session_rating = 0
166
 
167
+ test_df = pd.read_csv("/Users/carlosito/Library/CloudStorage/OneDrive-Personal/AIT material/99-AIT-thesis/aitGPT/test_db",
168
+ index_col=0)
169
+ test_df.sort_values(by = ['timestamp'],
170
+ axis=0,
171
+ ascending=False,
172
+ inplace=True)
173
+ st.dataframe(test_df)