relisora commited on
Commit
f1dfd3c
·
unverified ·
1 Parent(s): 4618fdf

display model name

Browse files
Files changed (1) hide show
  1. app.py +24 -5
app.py CHANGED
@@ -8,7 +8,12 @@ import requests
8
  import inspect
9
  import pandas as pd
10
 
11
- from agent import ANTHROPIC_MODEL_CHOICES, DEFAULT_ANTHROPIC_MODEL_ID, BasicAgent
 
 
 
 
 
12
 
13
  # (Keep Constants as is)
14
  # --- Constants ---
@@ -19,6 +24,15 @@ TOTAL_REQUESTS_PER_MINUTE = int(os.getenv("AGENT_REQUESTS_PER_MINUTE", "30"))
19
  _thread_local = threading.local()
20
 
21
 
 
 
 
 
 
 
 
 
 
22
  def get_worker_agent(model_id: str | None, requests_per_minute: int) -> BasicAgent:
23
  """One agent per worker thread: a CodeAgent's memory cannot be shared across runs in flight."""
24
  agent = getattr(_thread_local, "agent", None)
@@ -72,7 +86,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None, model_id: str, concurre
72
  worker_rpm = max(1, TOTAL_REQUESTS_PER_MINUTE // workers)
73
  try:
74
  # Fail fast on bad model configuration; workers build their own agents.
75
- BasicAgent(model_id=model_id)
76
  except Exception as e:
77
  print(f"Error instantiating agent: {e}")
78
  yield f"Error initializing agent: {e}", None
@@ -83,7 +97,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None, model_id: str, concurre
83
 
84
  # 2. Fetch Questions
85
  print(f"Fetching questions from: {questions_url}")
86
- yield "Fetching questions...", None
87
  try:
88
  response = requests.get(questions_url, timeout=15)
89
  response.raise_for_status()
@@ -119,8 +133,9 @@ def run_and_submit_all( profile: gr.OAuthProfile | None, model_id: str, concurre
119
  total = len(questions)
120
  rows: list[dict | None] = [None] * total
121
  started_all = time.monotonic()
122
- print(f"Running agent on {total} questions with {workers} worker(s)...")
123
- yield f"Running agent on {total} questions with {workers} worker(s)...", None
 
124
 
125
  with ThreadPoolExecutor(max_workers=workers) as pool:
126
  futures = {
@@ -139,6 +154,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None, model_id: str, concurre
139
  "Submitted Answer": display,
140
  }
141
  yield (
 
142
  f"Answered {done}/{total} questions "
143
  f"({time.monotonic() - started_all:.0f}s elapsed)...",
144
  pd.DataFrame([row for row in rows if row]),
@@ -167,6 +183,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None, model_id: str, concurre
167
  final_status = (
168
  f"Submission Successful!\n"
169
  f"User: {result_data.get('username')}\n"
 
170
  f"Overall Score: {result_data.get('score', 'N/A')}% "
171
  f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
172
  f"Message: {result_data.get('message', 'No message received.')}"
@@ -220,6 +237,8 @@ with gr.Blocks() as demo:
220
  """
221
  )
222
 
 
 
223
  gr.LoginButton()
224
 
225
  model_dropdown = gr.Dropdown(
 
8
  import inspect
9
  import pandas as pd
10
 
11
+ from agent import (
12
+ ANTHROPIC_MODEL_CHOICES,
13
+ DEFAULT_ANTHROPIC_MODEL_ID,
14
+ DEFAULT_MODEL_ID,
15
+ BasicAgent,
16
+ )
17
 
18
  # (Keep Constants as is)
19
  # --- Constants ---
 
24
  _thread_local = threading.local()
25
 
26
 
27
+ def describe_backend() -> str:
28
+ if os.getenv("ANTHROPIC_API_KEY"):
29
+ return f"**Backend:** Anthropic (`ANTHROPIC_API_KEY` found) — default model `{DEFAULT_ANTHROPIC_MODEL_ID}`"
30
+ return (
31
+ "**Backend:** Hugging Face Inference (no `ANTHROPIC_API_KEY` set) — default model "
32
+ f"`{os.getenv('HF_MODEL_ID') or DEFAULT_MODEL_ID}`"
33
+ )
34
+
35
+
36
  def get_worker_agent(model_id: str | None, requests_per_minute: int) -> BasicAgent:
37
  """One agent per worker thread: a CodeAgent's memory cannot be shared across runs in flight."""
38
  agent = getattr(_thread_local, "agent", None)
 
86
  worker_rpm = max(1, TOTAL_REQUESTS_PER_MINUTE // workers)
87
  try:
88
  # Fail fast on bad model configuration; workers build their own agents.
89
+ resolved_model = BasicAgent(model_id=model_id).model_id
90
  except Exception as e:
91
  print(f"Error instantiating agent: {e}")
92
  yield f"Error initializing agent: {e}", None
 
97
 
98
  # 2. Fetch Questions
99
  print(f"Fetching questions from: {questions_url}")
100
+ yield f"Model: {resolved_model}\nFetching questions...", None
101
  try:
102
  response = requests.get(questions_url, timeout=15)
103
  response.raise_for_status()
 
133
  total = len(questions)
134
  rows: list[dict | None] = [None] * total
135
  started_all = time.monotonic()
136
+ run_header = f"Model: {resolved_model} | {workers} parallel worker(s)"
137
+ print(f"Running agent on {total} questions. {run_header}")
138
+ yield f"{run_header}\nRunning agent on {total} questions...", None
139
 
140
  with ThreadPoolExecutor(max_workers=workers) as pool:
141
  futures = {
 
154
  "Submitted Answer": display,
155
  }
156
  yield (
157
+ f"{run_header}\n"
158
  f"Answered {done}/{total} questions "
159
  f"({time.monotonic() - started_all:.0f}s elapsed)...",
160
  pd.DataFrame([row for row in rows if row]),
 
183
  final_status = (
184
  f"Submission Successful!\n"
185
  f"User: {result_data.get('username')}\n"
186
+ f"Model: {resolved_model}\n"
187
  f"Overall Score: {result_data.get('score', 'N/A')}% "
188
  f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
189
  f"Message: {result_data.get('message', 'No message received.')}"
 
237
  """
238
  )
239
 
240
+ gr.Markdown(describe_backend())
241
+
242
  gr.LoginButton()
243
 
244
  model_dropdown = gr.Dropdown(