pathmohd123 commited on
Commit
b86ce06
Β·
verified Β·
1 Parent(s): 7975e95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -13,7 +13,6 @@ load_dotenv()
13
  openai.api_key = os.getenv("OPENAI_API_KEY")
14
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
15
 
16
-
17
  # ──────────────── Utility: Python Executor ────────────────
18
  def python_exec(code: str) -> str:
19
  try:
@@ -27,7 +26,6 @@ def python_exec(code: str) -> str:
27
  except Exception:
28
  return "Error during Python execution:\n" + traceback.format_exc()
29
 
30
-
31
  # ──────────────── Function Schema ────────────────
32
  function_definitions = [
33
  {
@@ -46,7 +44,6 @@ function_definitions = [
46
  }
47
  ]
48
 
49
-
50
  # ──────────────── Agent Class ────────────────
51
  class BasicAgent:
52
  def __init__(self):
@@ -114,7 +111,6 @@ class BasicAgent:
114
  else:
115
  return first_msg.content.strip()
116
 
117
-
118
  # ──────────────── API Helpers ────────────────
119
  def get_all_questions(api_url: str) -> list[dict]:
120
  resp = requests.get(f"{api_url}/questions", timeout=15)
@@ -131,11 +127,13 @@ def submit_answers(api_url: str, username: str, code_link: str, answers: list[di
131
  resp.raise_for_status()
132
  return resp.json()
133
 
134
-
135
  # ──────────────── Gradio Evaluation Logic ────────────────
136
  def run_and_submit_all(profile: Optional[gr.OAuthProfile]):
137
  if profile:
138
- username = profile.username.strip()
 
 
 
139
  else:
140
  return "❌ Please log in to Hugging Face using the button above.", None
141
 
@@ -193,7 +191,6 @@ def run_and_submit_all(profile: Optional[gr.OAuthProfile]):
193
  )
194
  return final_status, pd.DataFrame(results_log)
195
 
196
-
197
  # ──────────────── Gradio UI ────────────────
198
  with gr.Blocks() as demo:
199
  gr.Markdown("# 🧠 Basic Agent Evaluation")
@@ -219,7 +216,6 @@ with gr.Blocks() as demo:
219
  outputs=[status_output, results_table]
220
  )
221
 
222
-
223
  # ──────────────── Launch App ────────────────
224
  if __name__ == "__main__":
225
  space_host = os.getenv("SPACE_HOST")
@@ -238,4 +234,4 @@ if __name__ == "__main__":
238
  print("ℹ️ SPACE_ID not found")
239
 
240
  print("Launching Gradio Interface...")
241
- demo.launch(debug=True, server_name="0.0.0.0", server_port=7860)
 
13
  openai.api_key = os.getenv("OPENAI_API_KEY")
14
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
15
 
 
16
  # ──────────────── Utility: Python Executor ────────────────
17
  def python_exec(code: str) -> str:
18
  try:
 
26
  except Exception:
27
  return "Error during Python execution:\n" + traceback.format_exc()
28
 
 
29
  # ──────────────── Function Schema ────────────────
30
  function_definitions = [
31
  {
 
44
  }
45
  ]
46
 
 
47
  # ──────────────── Agent Class ────────────────
48
  class BasicAgent:
49
  def __init__(self):
 
111
  else:
112
  return first_msg.content.strip()
113
 
 
114
  # ──────────────── API Helpers ────────────────
115
  def get_all_questions(api_url: str) -> list[dict]:
116
  resp = requests.get(f"{api_url}/questions", timeout=15)
 
127
  resp.raise_for_status()
128
  return resp.json()
129
 
 
130
  # ──────────────── Gradio Evaluation Logic ────────────────
131
  def run_and_submit_all(profile: Optional[gr.OAuthProfile]):
132
  if profile:
133
+ if isinstance(profile, dict):
134
+ username = profile.get("preferred_username", "").strip()
135
+ else:
136
+ username = str(profile).strip()
137
  else:
138
  return "❌ Please log in to Hugging Face using the button above.", None
139
 
 
191
  )
192
  return final_status, pd.DataFrame(results_log)
193
 
 
194
  # ──────────────── Gradio UI ────────────────
195
  with gr.Blocks() as demo:
196
  gr.Markdown("# 🧠 Basic Agent Evaluation")
 
216
  outputs=[status_output, results_table]
217
  )
218
 
 
219
  # ──────────────── Launch App ────────────────
220
  if __name__ == "__main__":
221
  space_host = os.getenv("SPACE_HOST")
 
234
  print("ℹ️ SPACE_ID not found")
235
 
236
  print("Launching Gradio Interface...")
237
+ demo.launch(debug=True, server_name="0.0.0.0", server_port=7860)