Jofthomas commited on
Commit
4021bf3
·
verified ·
1 Parent(s): f6f7832

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -42,6 +42,26 @@ class BasicAgent:
42
 
43
  # --- Gradio UI and Logic ---
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  def run_and_submit_all( profile: gr.OAuthProfile | None):
46
  """
47
  Fetches all questions, runs the BasicAgent on them, submits all answers,
@@ -67,7 +87,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
67
  except Exception as e:
68
  print(f"Error instantiating agent or getting repr: {e}")
69
  return f"Error initializing agent: {e}", None
70
-
71
  # 2. Fetch All Questions
72
  print(f"Fetching questions from: {questions_url}")
73
  try:
 
42
 
43
  # --- Gradio UI and Logic ---
44
 
45
+ def get_current_script_content() -> str:
46
+ """Attempts to read and return the content of the currently running script."""
47
+ try:
48
+ # __file__ holds the path to the current script
49
+ script_path = os.path.abspath(__file__)
50
+ print(f"Reading script content from: {script_path}")
51
+ with open(script_path, 'r', encoding='utf-8') as f:
52
+ return f.read()
53
+ except NameError:
54
+ # __file__ is not defined (e.g., running in an interactive interpreter)
55
+ print("Warning: __file__ is not defined. Cannot read script content.")
56
+ return "# Agent code unavailable: __file__ not defined"
57
+ except FileNotFoundError:
58
+ print(f"Warning: Script file '{script_path}' not found.")
59
+ return f"# Agent code unavailable: Script file not found at {script_path}"
60
+ except Exception as e:
61
+ print(f"Error reading script file '{script_path}': {e}")
62
+ return f"# Agent code unavailable: Error reading script file: {e}"
63
+
64
+
65
  def run_and_submit_all( profile: gr.OAuthProfile | None):
66
  """
67
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
87
  except Exception as e:
88
  print(f"Error instantiating agent or getting repr: {e}")
89
  return f"Error initializing agent: {e}", None
90
+ agent_code=get_current_script_content()
91
  # 2. Fetch All Questions
92
  print(f"Fetching questions from: {questions_url}")
93
  try: