Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,26 +14,25 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
-
print("Initializing
|
| 18 |
-
# Load the
|
| 19 |
-
self.qa_pipeline = pipeline("
|
| 20 |
|
| 21 |
-
def __call__(self, question: str) -> str:
|
| 22 |
"""
|
| 23 |
-
Process the question using
|
| 24 |
"""
|
| 25 |
-
# Create a clearer and more direct prompt
|
| 26 |
-
prompt = f"Answer the following question: {question}"
|
| 27 |
-
|
| 28 |
try:
|
| 29 |
-
# Use the
|
| 30 |
-
result = self.qa_pipeline(
|
| 31 |
-
answer = result[
|
| 32 |
except Exception as e:
|
| 33 |
print(f"Error during QA: {e}")
|
| 34 |
answer = "Error processing question."
|
| 35 |
|
| 36 |
return answer
|
|
|
|
|
|
|
| 37 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 38 |
"""
|
| 39 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 14 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
+
print("Initializing BERT-based QA agent...")
|
| 18 |
+
# Load the BERT model fine-tuned on the SQuAD dataset
|
| 19 |
+
self.qa_pipeline = pipeline("question-answering", model="bert-large-uncased-whole-word-masking-finetuned-squad")
|
| 20 |
|
| 21 |
+
def __call__(self, question: str, context: str) -> str:
|
| 22 |
"""
|
| 23 |
+
Process the question using the BERT model fine-tuned on SQuAD, and return an answer based on the context.
|
| 24 |
"""
|
|
|
|
|
|
|
|
|
|
| 25 |
try:
|
| 26 |
+
# Use the QA pipeline to get an answer based on the context and the question
|
| 27 |
+
result = self.qa_pipeline(question=question, context=context)
|
| 28 |
+
answer = result["answer"]
|
| 29 |
except Exception as e:
|
| 30 |
print(f"Error during QA: {e}")
|
| 31 |
answer = "Error processing question."
|
| 32 |
|
| 33 |
return answer
|
| 34 |
+
|
| 35 |
+
|
| 36 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 37 |
"""
|
| 38 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|