Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,25 +11,19 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
class BasicAgent:
|
| 13 |
def __init__(self):
|
| 14 |
-
print("Loading
|
| 15 |
self.assistant_model = pipeline(
|
| 16 |
"text2text-generation",
|
| 17 |
-
model="google/flan-t5-
|
| 18 |
-
tokenizer="google/flan-t5-
|
| 19 |
)
|
| 20 |
|
| 21 |
def __call__(self, question: str) -> str:
|
| 22 |
-
print(f"Answering: {question}")
|
| 23 |
try:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
response = self.assistant_model(prompt, max_length=150, do_sample=False)
|
| 27 |
-
answer = response[0]["generated_text"]
|
| 28 |
-
print(f"Answer: {answer}")
|
| 29 |
-
return answer.strip()
|
| 30 |
except Exception as e:
|
| 31 |
-
|
| 32 |
-
return f"Error generating answer: {e}"
|
| 33 |
|
| 34 |
|
| 35 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
|
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
class BasicAgent:
|
| 13 |
def __init__(self):
|
| 14 |
+
print("Loading model...")
|
| 15 |
self.assistant_model = pipeline(
|
| 16 |
"text2text-generation",
|
| 17 |
+
model="google/flan-t5-base",
|
| 18 |
+
tokenizer="google/flan-t5-base"
|
| 19 |
)
|
| 20 |
|
| 21 |
def __call__(self, question: str) -> str:
|
|
|
|
| 22 |
try:
|
| 23 |
+
response = self.assistant_model(f"Answer this:\n{question}", max_length=100)
|
| 24 |
+
return response[0]["generated_text"].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
+
return f"Error: {e}"
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|