Update app.py
Browse files
app.py
CHANGED
|
@@ -13,22 +13,22 @@ load_dotenv()
|
|
| 13 |
hf_token = os.getenv("HF_TOKEN")
|
| 14 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 15 |
|
| 16 |
-
# ββββββββββββββββ Load
|
| 17 |
try:
|
| 18 |
-
pipe = pipeline("text-generation", model="
|
| 19 |
except Exception as e:
|
| 20 |
raise RuntimeError(f"Model loading failed: {e}")
|
| 21 |
|
| 22 |
# ββββββββββββββββ Agent Class ββββββββββββββββ
|
| 23 |
-
class
|
| 24 |
def __init__(self):
|
| 25 |
-
print("β
|
| 26 |
|
| 27 |
def __call__(self, question: str) -> str:
|
| 28 |
try:
|
| 29 |
-
prompt = f"
|
| 30 |
output = pipe(prompt, max_new_tokens=100, do_sample=False)
|
| 31 |
-
return output[0]["generated_text"].split("
|
| 32 |
except Exception as e:
|
| 33 |
return f"LLM Error: {e}"
|
| 34 |
|
|
@@ -58,7 +58,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 58 |
code_link = f"https://huggingface.co/spaces/{space_id}/tree/main" if space_id else ""
|
| 59 |
|
| 60 |
try:
|
| 61 |
-
agent =
|
| 62 |
except Exception as e:
|
| 63 |
return f"β Error initializing agent: {e}", None
|
| 64 |
|
|
@@ -111,7 +111,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 111 |
|
| 112 |
# ββββββββββββββββ Gradio UI ββββββββββββββββ
|
| 113 |
with gr.Blocks() as demo:
|
| 114 |
-
gr.Markdown("# π§
|
| 115 |
gr.Markdown(
|
| 116 |
"""
|
| 117 |
**Instructions:**
|
|
|
|
| 13 |
hf_token = os.getenv("HF_TOKEN")
|
| 14 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 15 |
|
| 16 |
+
# ββββββββββββββββ Load Mistral Model ββββββββββββββββ
|
| 17 |
try:
|
| 18 |
+
pipe = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct-v0.1", token=hf_token)
|
| 19 |
except Exception as e:
|
| 20 |
raise RuntimeError(f"Model loading failed: {e}")
|
| 21 |
|
| 22 |
# ββββββββββββββββ Agent Class ββββββββββββββββ
|
| 23 |
+
class MistralAgent:
|
| 24 |
def __init__(self):
|
| 25 |
+
print("β
MistralAgent initialized.")
|
| 26 |
|
| 27 |
def __call__(self, question: str) -> str:
|
| 28 |
try:
|
| 29 |
+
prompt = f"[INST] {question} [/INST]"
|
| 30 |
output = pipe(prompt, max_new_tokens=100, do_sample=False)
|
| 31 |
+
return output[0]["generated_text"].split("[/INST]")[-1].strip()
|
| 32 |
except Exception as e:
|
| 33 |
return f"LLM Error: {e}"
|
| 34 |
|
|
|
|
| 58 |
code_link = f"https://huggingface.co/spaces/{space_id}/tree/main" if space_id else ""
|
| 59 |
|
| 60 |
try:
|
| 61 |
+
agent = MistralAgent()
|
| 62 |
except Exception as e:
|
| 63 |
return f"β Error initializing agent: {e}", None
|
| 64 |
|
|
|
|
| 111 |
|
| 112 |
# ββββββββββββββββ Gradio UI ββββββββββββββββ
|
| 113 |
with gr.Blocks() as demo:
|
| 114 |
+
gr.Markdown("# π§ Mistral-7B Agent Evaluation")
|
| 115 |
gr.Markdown(
|
| 116 |
"""
|
| 117 |
**Instructions:**
|