ping98k commited on
Commit
66f49ec
·
1 Parent(s): 57d022a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -2
main.py CHANGED
@@ -4,6 +4,7 @@ import os, json, re, ast, gradio as gr
4
  from concurrent.futures import ThreadPoolExecutor, as_completed
5
  from tqdm import tqdm
6
  from litellm import completion
 
7
 
8
  NUM_TOP_PICKS_DEFAULT = int(os.getenv("NUM_TOP_PICKS", 5))
9
  POOL_SIZE_DEFAULT = int(os.getenv("POOL_SIZE", 10))
@@ -33,10 +34,12 @@ def run_tournament(instruction_input, criteria_input, n_gen, num_top_picks, pool
33
  pool_size = int(pool_size)
34
  max_workers = int(max_workers)
35
  process_log = []
 
 
36
  def log(msg):
37
  process_log.append(msg)
38
  tqdm.write(msg)
39
- yield "\n".join(process_log), ""
40
  yield from log("Generating players …")
41
  all_players = generate_players(instruction, n_gen)
42
  yield from log(f"{len(all_players)} players generated")
@@ -64,6 +67,9 @@ Output:
64
  yield from log("Scoring players …")
65
  with ThreadPoolExecutor(max_workers=max_workers) as ex:
66
  scores = {p: s for p, s in zip(all_players, list(tqdm(ex.map(score, all_players), total=len(all_players))))}
 
 
 
67
  top_players = sorted(all_players, key=scores.get, reverse=True)[:pool_size]
68
  yield from log(f"Filtered to {len(top_players)} players with best scores")
69
  def prompt_play(a, b):
@@ -125,7 +131,8 @@ Players:
125
  yield from log("Running tournament …")
126
  with ThreadPoolExecutor(max_workers=max_workers) as ex:
127
  top_k = get_top(top_players, ex)
128
- yield "\n".join(process_log + ["Done"]), "\n\n\n=====================================================\n\n\n".join(top_k)
 
129
 
130
  demo = gr.Interface(
131
  fn=run_tournament,
@@ -139,6 +146,7 @@ demo = gr.Interface(
139
  ],
140
  outputs=[
141
  gr.Textbox(lines=10, label="Process"),
 
142
  gr.Textbox(lines=50, label="Top picks")
143
  ]
144
  )
 
4
  from concurrent.futures import ThreadPoolExecutor, as_completed
5
  from tqdm import tqdm
6
  from litellm import completion
7
+ import matplotlib.pyplot as plt
8
 
9
  NUM_TOP_PICKS_DEFAULT = int(os.getenv("NUM_TOP_PICKS", 5))
10
  POOL_SIZE_DEFAULT = int(os.getenv("POOL_SIZE", 10))
 
34
  pool_size = int(pool_size)
35
  max_workers = int(max_workers)
36
  process_log = []
37
+ hist_fig = None
38
+ top_picks_str = ""
39
  def log(msg):
40
  process_log.append(msg)
41
  tqdm.write(msg)
42
+ yield "\n".join(process_log), hist_fig, top_picks_str
43
  yield from log("Generating players …")
44
  all_players = generate_players(instruction, n_gen)
45
  yield from log(f"{len(all_players)} players generated")
 
67
  yield from log("Scoring players …")
68
  with ThreadPoolExecutor(max_workers=max_workers) as ex:
69
  scores = {p: s for p, s in zip(all_players, list(tqdm(ex.map(score, all_players), total=len(all_players))))}
70
+ hist_fig = plt.figure()
71
+ plt.hist(list(scores.values()), bins=10)
72
+ yield from log("Histogram generated")
73
  top_players = sorted(all_players, key=scores.get, reverse=True)[:pool_size]
74
  yield from log(f"Filtered to {len(top_players)} players with best scores")
75
  def prompt_play(a, b):
 
131
  yield from log("Running tournament …")
132
  with ThreadPoolExecutor(max_workers=max_workers) as ex:
133
  top_k = get_top(top_players, ex)
134
+ top_picks_str = "\n\n\n=====================================================\n\n\n".join(top_k)
135
+ yield "\n".join(process_log + ["Done"]), hist_fig, top_picks_str
136
 
137
  demo = gr.Interface(
138
  fn=run_tournament,
 
146
  ],
147
  outputs=[
148
  gr.Textbox(lines=10, label="Process"),
149
+ gr.Plot(label="Score Distribution"),
150
  gr.Textbox(lines=50, label="Top picks")
151
  ]
152
  )