Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,18 +9,25 @@ from transformers import pipeline
|
|
9 |
|
10 |
pipe = pipeline("question-answering", model="Intel/dynamic_tinybert")
|
11 |
|
12 |
-
# Define the function to answer questions
|
13 |
def get_answer(text):
|
14 |
result = pipe(question=text, context=knowledge_base_text)
|
15 |
-
|
|
|
|
|
16 |
|
17 |
# Define the Gradio interface
|
18 |
def chatbot_interface(Question):
|
19 |
-
answer = get_answer(Question)
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
knowledge_base_text = """
|
23 |
-
|
|
|
24 |
3GGT : The 3 Great Growth Things ;
|
25 |
4D : Four "D" model ;
|
26 |
60 day crops : 60 day crops ;
|
@@ -2185,10 +2192,6 @@ ZW06 : BAT Zimbabwe - Harare ;
|
|
2185 |
APSCSC : Asia Pacific Supply Chain Service Centre ;
|
2186 |
NAA : North Asia Area ;
|
2187 |
|
2188 |
-
|
2189 |
-
- Service desk is located at HO 1st floor & Annes near basketball ground.
|
2190 |
-
- for SAP , wifi , network related issue , you should contact Md. Monirul Islam & his contact number 01730372426
|
2191 |
-
- CTC stands for Ceylon Tobacco Company PLC.
|
2192 |
"""
|
2193 |
|
2194 |
iface = gr.Interface(
|
|
|
9 |
|
10 |
pipe = pipeline("question-answering", model="Intel/dynamic_tinybert")
|
11 |
|
|
|
12 |
def get_answer(text):
|
13 |
result = pipe(question=text, context=knowledge_base_text)
|
14 |
+
answer = result["answer"]
|
15 |
+
confidence = result["score"]
|
16 |
+
return answer, confidence
|
17 |
|
18 |
# Define the Gradio interface
|
19 |
def chatbot_interface(Question):
|
20 |
+
answer, confidence = get_answer(Question)
|
21 |
+
if confidence < 0.2:
|
22 |
+
response = "Not found in the knowledge base"
|
23 |
+
else:
|
24 |
+
response = f"Answer: {answer}"
|
25 |
+
return response
|
26 |
+
|
27 |
|
28 |
knowledge_base_text = """
|
29 |
+
CTC : Ceylon Tobacco Company ;
|
30 |
+
PTC : Pakistan Tobacco Company ;
|
31 |
3GGT : The 3 Great Growth Things ;
|
32 |
4D : Four "D" model ;
|
33 |
60 day crops : 60 day crops ;
|
|
|
2192 |
APSCSC : Asia Pacific Supply Chain Service Centre ;
|
2193 |
NAA : North Asia Area ;
|
2194 |
|
|
|
|
|
|
|
|
|
2195 |
"""
|
2196 |
|
2197 |
iface = gr.Interface(
|