Synnove commited on
Commit
335a818
·
verified ·
1 Parent(s): 00ab3f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -2
app.py CHANGED
@@ -69,7 +69,7 @@ agent_codeagent = CodeAgent(
69
  )
70
 
71
 
72
- def run_and_submit_one():
73
  # 1. Instantiate Agent ( modify this part to create your agent)
74
  try:
75
  #agent = BasicAgent()
@@ -110,5 +110,37 @@ def run_and_submit_one():
110
  print("Agent did not produce any answers to submit.")
111
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
112
 
113
- run_and_submit_one()
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  )
70
 
71
 
72
+ #def run_and_submit_one():
73
  # 1. Instantiate Agent ( modify this part to create your agent)
74
  try:
75
  #agent = BasicAgent()
 
110
  print("Agent did not produce any answers to submit.")
111
  return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
112
 
113
+ #run_and_submit_one()
114
 
115
+ # Gradio handler that runs the agent
116
+ def run_once(state):
117
+ if state is not None:
118
+ return "Already run once. Refresh to rerun.", state
119
+
120
+ status_message, questions_data = load_questions_from_file()
121
+ if questions_data is None or len(questions_data) == 0:
122
+ return "No questions found or failed to load.", None
123
+
124
+ question = questions_data[0]
125
+ question_text = question["question"]
126
+ task_id = question["task_id"]
127
+
128
+ try:
129
+ answer = agent_codeagent(question_text)
130
+ output = f"Answer to task {task_id}:\n{answer}"
131
+ return output, output
132
+ except Exception as e:
133
+ return f"Error running agent: {e}", None
134
+
135
+ # Create Gradio interface
136
+ with gr.Blocks() as demo:
137
+ gr.Markdown("## Run AI Agent Once")
138
+
139
+ output_text = gr.Textbox(label="Agent Output", lines=10)
140
+ run_button = gr.Button("Run Agent")
141
+ state = gr.State() # cache variable to prevent re-runs
142
+
143
+ run_button.click(fn=run_once, inputs=state, outputs=[output_text, state])
144
+
145
+ # Launch the interface
146
+ demo.launch()