Spaces:
Sleeping
Sleeping
SirinootKK
commited on
Commit
·
045864b
1
Parent(s):
846bf0f
fix app file
Browse files
app.py
CHANGED
@@ -151,6 +151,17 @@ class Chatbot:
|
|
151 |
Answer = Answers[0]
|
152 |
|
153 |
return Answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
|
156 |
# Function to predict using BERT embedding
|
@@ -207,10 +218,10 @@ bot = ChatbotModel()
|
|
207 |
|
208 |
EXAMPLE_PATH = ["หลิน ไห่เฟิง มีชื่อเรียกอีกชื่อว่าอะไร" , "ใครเป็นผู้ตั้งสภาเศรษฐกิจโลกขึ้นในปี พ.ศ. 2514 โดยทุกปีจะมีการประชุมที่ประเทศสวิตเซอร์แลนด์", "โปรดิวเซอร์ของอัลบั้มตลอดกาล ของวงคีรีบูนคือใคร", "สกุลเดิมของหม่อมครูนุ่ม นวรัตน ณ อยุธยา คืออะไร"]
|
209 |
|
210 |
-
demoFaiss = gr.ChatInterface(fn=bot._chatbot.predict_faiss, examples=EXAMPLE_PATH)
|
211 |
-
demoBert = gr.ChatInterface(fn=bot._chatbot.predict_bert_embedding,examples=EXAMPLE_PATH)
|
212 |
-
demoSemantic = gr.ChatInterface(fn=bot._chatbot.predict_semantic_search,examples=EXAMPLE_PATH)
|
213 |
-
demoWithoutFiss = gr.ChatInterface(fn=bot._chatbot.predict_without_faiss,examples=EXAMPLE_PATH)
|
214 |
|
215 |
demo = gr.TabbedInterface([demoFaiss, demoWithoutFiss, demoBert, demoSemantic], ["Faiss", "Model", "Faiss & Model", "Semantic Search & Model"])
|
216 |
demo.launch()
|
|
|
151 |
Answer = Answers[0]
|
152 |
|
153 |
return Answer
|
154 |
+
|
155 |
+
def predict_faiss(self, message):
|
156 |
+
message = message.strip()
|
157 |
+
question_vector = self.get_embeddings([message])
|
158 |
+
question_vector = self.prepare_sentences_vector([question_vector])
|
159 |
+
similar_questions, similar_contexts, distances, indices = self.faiss_search(question_vector)
|
160 |
+
Answers = [self.df['Answer'][i] for i in indices[0]]
|
161 |
+
Answer = Answers[0]
|
162 |
+
|
163 |
+
return Answer
|
164 |
+
|
165 |
|
166 |
|
167 |
# Function to predict using BERT embedding
|
|
|
218 |
|
219 |
EXAMPLE_PATH = ["หลิน ไห่เฟิง มีชื่อเรียกอีกชื่อว่าอะไร" , "ใครเป็นผู้ตั้งสภาเศรษฐกิจโลกขึ้นในปี พ.ศ. 2514 โดยทุกปีจะมีการประชุมที่ประเทศสวิตเซอร์แลนด์", "โปรดิวเซอร์ของอัลบั้มตลอดกาล ของวงคีรีบูนคือใคร", "สกุลเดิมของหม่อมครูนุ่ม นวรัตน ณ อยุธยา คืออะไร"]
|
220 |
|
221 |
+
demoFaiss = gr.ChatInterface(fn=bot._chatbot.predict_faiss, examples=EXAMPLE_PATH,inputs="text",outputs="text")
|
222 |
+
demoBert = gr.ChatInterface(fn=bot._chatbot.predict_bert_embedding,examples=EXAMPLE_PATH,inputs="text",outputs="text")
|
223 |
+
demoSemantic = gr.ChatInterface(fn=bot._chatbot.predict_semantic_search,examples=EXAMPLE_PATH,inputs="text",outputs="text")
|
224 |
+
demoWithoutFiss = gr.ChatInterface(fn=bot._chatbot.predict_without_faiss,examples=EXAMPLE_PATH,inputs="text",outputs="text")
|
225 |
|
226 |
demo = gr.TabbedInterface([demoFaiss, demoWithoutFiss, demoBert, demoSemantic], ["Faiss", "Model", "Faiss & Model", "Semantic Search & Model"])
|
227 |
demo.launch()
|