dschandra commited on
Commit
4135464
·
verified ·
1 Parent(s): 14edf0d

Delete knowledge_base.py

Browse files
Files changed (1) hide show
  1. knowledge_base.py +0 -33
knowledge_base.py DELETED
@@ -1,33 +0,0 @@
1
- import requests
2
- from transformers import pipeline
3
-
4
- # Load the model and tokenizer using Hugging Face's pipeline
5
- qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
6
-
7
- def load_qa_model():
8
- # Initialize any model settings or variables, if needed
9
- return qa_pipeline
10
-
11
- def get_answer_from_knowledge_base(question):
12
- """
13
- This function uses a Hugging Face model (DistilBERT) for question answering
14
- from a given context.
15
- """
16
- try:
17
- # Example: Using a static context for the model to search for answers
18
- context = """
19
- Andhra Pradesh (AP) is a state in southern India. The current Chief Minister of Andhra Pradesh is Y. S. Jagan Mohan Reddy.
20
- He assumed office in May 2019. Jagan Mohan Reddy is from the Yuvajana Sramika Rythu Congress Party (YSRCP).
21
- """
22
-
23
- # Using the question-answering pipeline from Hugging Face
24
- result = qa_pipeline(question=question, context=context)
25
-
26
- # Extract and return the answer from the result
27
- if result['score'] > 0.1: # Only return answer if the model is confident
28
- return result['answer']
29
- else:
30
- return None
31
- except Exception as e:
32
- print(f"Error occurred: {e}")
33
- return "Sorry, I couldn't fetch data at the moment. Please try again later."