Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,21 +8,26 @@ from transformers import pipeline
|
|
| 8 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 9 |
|
| 10 |
# --- Basic Agent Definition ---
|
| 11 |
-
class
|
| 12 |
def __init__(self):
|
| 13 |
-
print("
|
| 14 |
self.qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
| 15 |
|
| 16 |
def __call__(self, question: str, context: str = None) -> str:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 28 |
space_id = os.getenv("SPACE_ID")
|
|
|
|
| 8 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 9 |
|
| 10 |
# --- Basic Agent Definition ---
|
| 11 |
+
class GeneralAgent:
|
| 12 |
def __init__(self):
|
| 13 |
+
print("Initializing general QA agent...")
|
| 14 |
self.qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
| 15 |
|
| 16 |
def __call__(self, question: str, context: str = None) -> str:
|
| 17 |
+
"""
|
| 18 |
+
Process the question and return an answer based on the given context.
|
| 19 |
+
Uses a prompt template to provide a clear structure for the answer.
|
| 20 |
+
"""
|
| 21 |
+
prompt = """
|
| 22 |
+
You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 23 |
+
"""
|
| 24 |
+
question_with_prompt = f"{prompt}\nQuestion: {question}\nContext: {context if context else 'No context provided.'}\n"
|
| 25 |
+
|
| 26 |
+
result = self.qa_pipeline(question=question_with_prompt, context=context)
|
| 27 |
+
answer = result["answer"]
|
| 28 |
+
|
| 29 |
+
# This is where you can modify the final format of the answer if needed.
|
| 30 |
+
return f"FINAL ANSWER: {answer}"
|
| 31 |
|
| 32 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
| 33 |
space_id = os.getenv("SPACE_ID")
|