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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -12,13 +12,29 @@ 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
- self.endpoint = "https://jcleee-first-agent-template.hf.space/run/predict" # Replace with your actual Space URL
 
16
 
17
  def __call__(self, question: str) -> str:
18
  try:
19
- response = requests.post(f"{self.endpoint}", json={"data": [question]}, timeout=60) # new change: removed /run
 
 
 
 
 
 
 
 
 
 
 
20
  result = response.json()
21
- return result["data"][0] if "data" in result else "null"
 
 
 
 
22
  except Exception as e:
23
  return f"Error: {e}"
24
 
 
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