Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,14 +10,24 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
|
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
-
print("BasicAgent
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
print(f"Agent received question
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
+
from transformers import pipeline
|
| 14 |
+
|
| 15 |
class BasicAgent:
|
| 16 |
def __init__(self):
|
| 17 |
+
print("Initializing BasicAgent with a transformer model...")
|
| 18 |
+
self.qa_pipeline = pipeline("text-generation", model="gpt2") # You can change model if needed
|
| 19 |
+
|
| 20 |
def __call__(self, question: str) -> str:
|
| 21 |
+
print(f"Agent received question: {question}")
|
| 22 |
+
try:
|
| 23 |
+
response = self.qa_pipeline(question, max_length=100, do_sample=True)
|
| 24 |
+
answer = response[0]["generated_text"]
|
| 25 |
+
print(f"Generated answer: {answer}")
|
| 26 |
+
return answer.strip()
|
| 27 |
+
except Exception as e:
|
| 28 |
+
print(f"Error during model generation: {e}")
|
| 29 |
+
return f"Error generating answer: {e}"
|
| 30 |
+
|
| 31 |
|
| 32 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 33 |
"""
|