Update app.py
#199
by
azaj
- opened
app.py
CHANGED
|
@@ -12,12 +12,26 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
+
print("Loading Hugging Face LLM pipeline...")
|
| 16 |
+
self.pipe = pipeline(
|
| 17 |
+
"text-generation",
|
| 18 |
+
model="mistralai/Mistral-7B-Instruct-v0.1",
|
| 19 |
+
device=0 if torch.cuda.is_available() else -1,
|
| 20 |
+
max_new_tokens=256,
|
| 21 |
+
do_sample=True,
|
| 22 |
+
temperature=0.7
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
def __call__(self, question: str) -> str:
|
| 26 |
+
prompt = f"[INST] {question.strip()} [/INST]"
|
| 27 |
+
try:
|
| 28 |
+
response = self.pipe(prompt)[0]["generated_text"]
|
| 29 |
+
# Post-processing to trim the prompt out of the response
|
| 30 |
+
answer = response.replace(prompt, "").strip()
|
| 31 |
+
print(f"Generated Answer: {answer[:80]}...")
|
| 32 |
+
return answer
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return f"Error: {e}"
|
| 35 |
|
| 36 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 37 |
"""
|