jcleee commited on
Commit
1d7021b
Β·
verified Β·
1 Parent(s): d648767

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -10,20 +10,32 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
13
  class BasicAgent:
14
  def __init__(self):
15
- host = os.getenv("SPACE_HOST", "https://jcleee-first-agent-template.hf.space")
16
- # <β€” use /api/predict here
17
- self.endpoint = f"https://{host}"
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
 
 
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
+ # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
  class BasicAgent:
15
  def __init__(self):
16
+ host = os.getenv("SPACE_HOST", "jcleee-first-agent-template.hf.space")
17
+ self.endpoint = f"https://{host}/run/predict"
 
18
 
19
  def __call__(self, question: str) -> str:
20
  try:
21
+ payload = {"data": [question], "fn_index": 0}
 
22
  response = requests.post(self.endpoint, json=payload, timeout=60)
23
+
24
+ # ←――――――――――――――――――――――――――――――――――――――――
25
+ # DEBUG LINES:
26
+ print("▢️ POST", self.endpoint)
27
+ print(" payload:", payload)
28
+ print(" status:", response.status_code)
29
+ raw = response.text
30
+ print(" raw response:", raw[:500])
31
+ # ―――――――――――――――――――――――――――――――――――――――――――→
32
+
33
  result = response.json()
34
+ if "data" in result:
35
+ return result["data"][0]
36
+ # if you see e.g. result["predictions"], pull from there instead
37
+ print("⚠️ no `data` key in result, keys are:", result.keys())
38
+ return "null"
39
  except Exception as e:
40
  return f"Error: {e}"
41