-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt_manager.py
More file actions
34 lines (25 loc) · 1017 Bytes
/
Copy pathprompt_manager.py
File metadata and controls
34 lines (25 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Creates a streamer class to pass prompts to the models. Prompts come from filepath var
"""
import pandas as pd
import random
class CSVPromptStreamer:
def __init__(self, filepath="data/prompts/unused_prompts2.csv"):
print(f"Loading and shuffling prompts from {filepath}...")
# Load the CSV
df = pd.read_csv(filepath)
# Grab the column that contains the prompt
self.prompts = df["prompt"].dropna().tolist()
# Shuffle immediately
random.shuffle(self.prompts)
self.index = 0
self.total_prompts = len(self.prompts)
print(f"Successfully loaded {self.total_prompts} prompts into memory.")
def get_next_prompt(self):
# Reshuffle if we hit the end of the list
if self.index >= self.total_prompts:
random.shuffle(self.prompts)
self.index = 0
prompt = self.prompts[self.index]
self.index += 1
return str(prompt)