Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,31 +15,30 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 15 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 16 |
class BasicAgent:
|
| 17 |
def __init__(self):
|
| 18 |
-
print("π Loading
|
| 19 |
self.llm = pipeline(
|
| 20 |
"text-generation",
|
| 21 |
-
model="
|
| 22 |
-
tokenizer="
|
| 23 |
max_new_tokens=200,
|
| 24 |
temperature=0,
|
| 25 |
-
device=0 if torch.cuda.is_available() else -1
|
| 26 |
)
|
| 27 |
-
print("β
|
| 28 |
|
| 29 |
def __call__(self, question: str) -> str:
|
| 30 |
print(f"π€ Agent received question: {question}")
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
try:
|
| 36 |
output = self.llm(prompt)[0]["generated_text"]
|
| 37 |
-
#
|
| 38 |
-
answer = output.
|
| 39 |
print(f"β
Answer: {answer}")
|
| 40 |
return answer
|
| 41 |
except Exception as e:
|
| 42 |
-
print(f"β Error: {e}")
|
| 43 |
return "I don't know"
|
| 44 |
|
| 45 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 15 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 16 |
class BasicAgent:
|
| 17 |
def __init__(self):
|
| 18 |
+
print("π Loading Zephyr 7B...")
|
| 19 |
self.llm = pipeline(
|
| 20 |
"text-generation",
|
| 21 |
+
model="HuggingFaceH4/zephyr-7b-beta",
|
| 22 |
+
tokenizer="HuggingFaceH4/zephyr-7b-beta",
|
| 23 |
max_new_tokens=200,
|
| 24 |
temperature=0,
|
| 25 |
+
device=0 if torch.cuda.is_available() else -1
|
| 26 |
)
|
| 27 |
+
print("β
Zephyr 7B Loaded.")
|
| 28 |
|
| 29 |
def __call__(self, question: str) -> str:
|
| 30 |
print(f"π€ Agent received question: {question}")
|
| 31 |
|
| 32 |
+
prompt = f"<|system|>You are a helpful assistant.<|user|>{question}<|assistant|>"
|
| 33 |
+
|
|
|
|
| 34 |
try:
|
| 35 |
output = self.llm(prompt)[0]["generated_text"]
|
| 36 |
+
# Post-process to remove prompt from output
|
| 37 |
+
answer = output.split("<|assistant|>")[-1].strip()
|
| 38 |
print(f"β
Answer: {answer}")
|
| 39 |
return answer
|
| 40 |
except Exception as e:
|
| 41 |
+
print(f"β Error generating response: {e}")
|
| 42 |
return "I don't know"
|
| 43 |
|
| 44 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|