jcleee commited on
Commit
9bdab4a
Β·
verified Β·
1 Parent(s): 6cf791a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -18
app.py CHANGED
@@ -12,32 +12,22 @@ 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
- host = os.getenv("SPACE_HOST", "jcleee-first-agent-template.hf.space")
16
- self.endpoint = f"https://{host}/run/predict"
 
17
 
18
  def __call__(self, question: str) -> str:
19
  try:
20
- payload = {"data": [question], "fn_index": 0}
 
21
  response = requests.post(self.endpoint, json=payload, timeout=60)
22
-
23
- # ←――――――――――――――――――――――――――――――――――――――――
24
- # DEBUG LINES:
25
- print("▢️ POST", self.endpoint)
26
- print(" payload:", payload)
27
- print(" status:", response.status_code)
28
- raw = response.text
29
- print(" raw response:", raw[:500])
30
- # ―――――――――――――――――――――――――――――――――――――――――――→
31
-
32
  result = response.json()
33
- if "data" in result:
34
- return result["data"][0]
35
- # if you see e.g. result["predictions"], pull from there instead
36
- print("⚠️ no `data` key in result, keys are:", result.keys())
37
- return "null"
38
  except Exception as e:
39
  return f"Error: {e}"
40
 
 
41
  def run_and_submit_all( profile: gr.OAuthProfile | None):
42
  """
43
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
  class BasicAgent:
14
  def __init__(self):
15
+ host = os.getenv("SPACE_HOST", "jcleee-final-assignment-template.hf.space")
16
+ # <β€” use /api/predict here
17
+ self.endpoint = f"https://{host}/api/predict"
18
 
19
  def __call__(self, question: str) -> str:
20
  try:
21
+ # you usually do NOT need fn_index for a single-Interface app
22
+ payload = {"data": [question]}
23
  response = requests.post(self.endpoint, json=payload, timeout=60)
24
+ response.raise_for_status()
 
 
 
 
 
 
 
 
 
25
  result = response.json()
26
+ return result["data"][0]
 
 
 
 
27
  except Exception as e:
28
  return f"Error: {e}"
29
 
30
+
31
  def run_and_submit_all( profile: gr.OAuthProfile | None):
32
  """
33
  Fetches all questions, runs the BasicAgent on them, submits all answers,