civerson916 commited on
Commit
0a8fce8
·
verified ·
1 Parent(s): f8feafc

Added asyncio.new_event_loop

Browse files
Files changed (2) hide show
  1. app.py +1 -7
  2. runner.py +5 -1
app.py CHANGED
@@ -6,8 +6,6 @@ from opentelemetry import trace
6
  from evaluator import Evaluator
7
  from runner import Runner
8
  from settings import Settings
9
- import asyncio
10
- import nest_asyncio
11
  import os
12
  import pandas as pd
13
  import gradio as gr
@@ -48,11 +46,7 @@ def run_one(profile: gr.OAuthProfile | None) -> pd.DataFrame:
48
  if not user_logged_in(profile):
49
  return LOGIN_MESSAGE, EMPTY_RESULTS_TABLE
50
  questions = [evaluator.get_one_question()]
51
- # Apply nest_asyncio to patch the event loop
52
- nest_asyncio.apply()
53
-
54
- # Now, call run_agent within an event loop
55
- results_df = asyncio.run(runner.run_agent(questions))
56
 
57
  def run_all(profile: gr.OAuthProfile | None) -> pd.DataFrame:
58
  if not user_logged_in(profile):
 
6
  from evaluator import Evaluator
7
  from runner import Runner
8
  from settings import Settings
 
 
9
  import os
10
  import pandas as pd
11
  import gradio as gr
 
46
  if not user_logged_in(profile):
47
  return LOGIN_MESSAGE, EMPTY_RESULTS_TABLE
48
  questions = [evaluator.get_one_question()]
49
+ return "Answer one random question...", runner.run_agent(questions)
 
 
 
 
50
 
51
  def run_all(profile: gr.OAuthProfile | None) -> pd.DataFrame:
52
  if not user_logged_in(profile):
runner.py CHANGED
@@ -53,7 +53,11 @@ class Runner():
53
  def run_agent(self, questions) -> pd.DataFrame:
54
  """Run the agent(s) async, save answers and return a dataframe"""
55
  # Assign questions to agents and wait
56
- loop = asyncio.get_running_loop()
 
 
 
 
57
 
58
  def run_tasks_in_thread():
59
  question_answer_pairs = loop.run_until_complete(
 
53
  def run_agent(self, questions) -> pd.DataFrame:
54
  """Run the agent(s) async, save answers and return a dataframe"""
55
  # Assign questions to agents and wait
56
+ try:
57
+ loop = asyncio.get_running_loop()
58
+ except RuntimeError: # No running loop, create one
59
+ loop = asyncio.new_event_loop()
60
+ asyncio.set_event_loop(loop)
61
 
62
  def run_tasks_in_thread():
63
  question_answer_pairs = loop.run_until_complete(