razanalsulami commited on
Commit
cfb36d4
·
verified ·
1 Parent(s): 1901b68

Update app

Browse files
Files changed (1) hide show
  1. app +7 -16
app CHANGED
@@ -1,4 +1,7 @@
1
- # Sample context and question
 
 
 
2
  context = """Saudi Arabia, officially known as the Kingdom of Saudi Arabia, is the largest country in the Middle East.
3
  It is bordered by Jordan, Iraq, Kuwait, Bahrain, Qatar, the United Arab Emirates, Oman, and Yemen.
4
  The capital city is Riyadh. Saudi Arabia is known for its vast deserts, including the Rub’ al Khali, also
@@ -9,19 +12,7 @@ is Arabic, and the currency is the Saudi riyal."""
9
 
10
  question = "What is the capital of Saudi Arabia?"
11
 
12
- # Function to extract the answer from the context
13
- def find_answer(context, question):
14
- if "capital" in question.lower():
15
- # Searching for the word "capital" in the context
16
- sentences = context.split(".")
17
- for sentence in sentences:
18
- if "capital" in sentence.lower():
19
- # Assuming the answer follows after the word "capital"
20
- words = sentence.split()
21
- if "capital" in words:
22
- index = words.index("capital")
23
- # Return the next word which should be the capital city
24
- return words[index + 3] # The word after 'capital city is'
25
 
26
- answer = find_answer(context, question)
27
- print(f"Answer: {answer}")
 
1
+ from transformers import pipeline
2
+
3
+ qa_pipeline = pipeline("question-answering")
4
+
5
  context = """Saudi Arabia, officially known as the Kingdom of Saudi Arabia, is the largest country in the Middle East.
6
  It is bordered by Jordan, Iraq, Kuwait, Bahrain, Qatar, the United Arab Emirates, Oman, and Yemen.
7
  The capital city is Riyadh. Saudi Arabia is known for its vast deserts, including the Rub’ al Khali, also
 
12
 
13
  question = "What is the capital of Saudi Arabia?"
14
 
15
+ answer = qa_pipeline(question=question, context=context)
16
+
17
+ print(f"Answer: {answer['answer']}")
 
 
 
 
 
 
 
 
 
 
18