Update app.py
Browse files
app.py
CHANGED
|
@@ -14,37 +14,37 @@ class HfApiModel:
|
|
| 14 |
raise ValueError("HF_TOKEN environment variable is missing.")
|
| 15 |
|
| 16 |
def __call__(self, prompt):
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
def generate(self, prompt, **kwargs):
|
| 50 |
return self.__call__(prompt)
|
|
@@ -96,7 +96,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 96 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main" if space_id else "Unknown"
|
| 97 |
|
| 98 |
try:
|
| 99 |
-
response = requests.get(questions_url, timeout=
|
| 100 |
response.raise_for_status()
|
| 101 |
questions_data = response.json()
|
| 102 |
if not questions_data:
|
|
@@ -153,7 +153,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 153 |
# Gradio UI
|
| 154 |
with gr.Blocks() as demo:
|
| 155 |
gr.Markdown("# 🤖 Basic Agent Evaluation Runner")
|
| 156 |
-
gr.Markdown("
|
| 157 |
|
| 158 |
gr.LoginButton()
|
| 159 |
run_button = gr.Button("▶️ Run Evaluation & Submit All Answers")
|
|
|
|
| 14 |
raise ValueError("HF_TOKEN environment variable is missing.")
|
| 15 |
|
| 16 |
def __call__(self, prompt):
|
| 17 |
+
# Handle prompt safely (ChatMessage, nested lists, etc.)
|
| 18 |
+
if hasattr(prompt, "content"):
|
| 19 |
+
prompt = prompt.content
|
| 20 |
+
elif isinstance(prompt, list):
|
| 21 |
+
flat_parts = []
|
| 22 |
+
for m in prompt:
|
| 23 |
+
if isinstance(m, list):
|
| 24 |
+
flat_parts.extend(str(sub) for sub in m)
|
| 25 |
+
elif hasattr(m, "content"):
|
| 26 |
+
flat_parts.append(str(m.content))
|
| 27 |
+
else:
|
| 28 |
+
flat_parts.append(str(m))
|
| 29 |
+
prompt = " ".join(flat_parts)
|
| 30 |
+
else:
|
| 31 |
+
prompt = str(prompt)
|
| 32 |
+
|
| 33 |
+
url = f"https://api-inference.huggingface.co/models/{self.model_name}"
|
| 34 |
+
headers = {"Authorization": f"Bearer {self.api_key}"}
|
| 35 |
+
payload = {
|
| 36 |
+
"inputs": prompt,
|
| 37 |
+
"options": {"wait_for_model": True}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
response = requests.post(url, headers=headers, json=payload, timeout=60)
|
| 41 |
+
response.raise_for_status()
|
| 42 |
+
output = response.json()
|
| 43 |
|
| 44 |
+
try:
|
| 45 |
+
return output[0]["generated_text"]
|
| 46 |
+
except Exception:
|
| 47 |
+
return f"ERROR: {output}"
|
| 48 |
|
| 49 |
def generate(self, prompt, **kwargs):
|
| 50 |
return self.__call__(prompt)
|
|
|
|
| 96 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main" if space_id else "Unknown"
|
| 97 |
|
| 98 |
try:
|
| 99 |
+
response = requests.get(questions_url, timeout=30)
|
| 100 |
response.raise_for_status()
|
| 101 |
questions_data = response.json()
|
| 102 |
if not questions_data:
|
|
|
|
| 153 |
# Gradio UI
|
| 154 |
with gr.Blocks() as demo:
|
| 155 |
gr.Markdown("# 🤖 Basic Agent Evaluation Runner")
|
| 156 |
+
gr.Markdown("Log in with your Hugging Face account, run your agent, and submit your answers.")
|
| 157 |
|
| 158 |
gr.LoginButton()
|
| 159 |
run_button = gr.Button("▶️ Run Evaluation & Submit All Answers")
|