Upload PE.py with huggingface_hub
Browse files
PE.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from tqdm import tqdm
|
| 3 |
+
import time
|
| 4 |
+
# Input files and directories
|
| 5 |
+
|
| 6 |
+
typ = "abstract"
|
| 7 |
+
|
| 8 |
+
input_file = "abstract_prompts.txt"
|
| 9 |
+
|
| 10 |
+
#selected_videos_nums = [0,20,40,60,80,120,140,150] #,,80,120,140,150
|
| 11 |
+
|
| 12 |
+
selected_videos_nums = [10,50,100] #,,80,120,140,150
|
| 13 |
+
tags = [1]
|
| 14 |
+
for selected_videos_num in selected_videos_nums:
|
| 15 |
+
for tag in tags:
|
| 16 |
+
rag_prompt_dir = f"rag_cot_prompt_ai_{typ}_rag_{selected_videos_num}_tags_{tag}_testset/" # rag_cot_prompt_ai_abstract_rag_50_tags_2_testset
|
| 17 |
+
output_dir = f"creation_rag_cot_prompt_ai_{typ}_rag_{selected_videos_num}_tags_{tag}_testset/"
|
| 18 |
+
script_file = "pipline.py"
|
| 19 |
+
# Create directories if they do not exist
|
| 20 |
+
os.makedirs(rag_prompt_dir, exist_ok=True)
|
| 21 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 22 |
+
# Read UserPrompts.txt
|
| 23 |
+
with open(input_file, "r", encoding="utf-8") as f:
|
| 24 |
+
prompts = f.readlines()
|
| 25 |
+
|
| 26 |
+
# # Process each prompt
|
| 27 |
+
for i, prompt in enumerate(tqdm(prompts,desc="Generating Prompts")):
|
| 28 |
+
prompt = prompt.strip()
|
| 29 |
+
output_path = os.path.join(rag_prompt_dir, f"{prompt}.txt")
|
| 30 |
+
if not prompt or os.path.exists(output_path): # Skip empty lines
|
| 31 |
+
continue
|
| 32 |
+
|
| 33 |
+
safe_filename = f"{prompt[:].replace(' ', '_').replace('/', '_')}.txt"
|
| 34 |
+
rag_prompt_file = os.path.join(rag_prompt_dir, safe_filename)
|
| 35 |
+
|
| 36 |
+
# Generate RAG Prompt
|
| 37 |
+
command = f"python {script_file} --USER_PROMPT \'{prompt}\' --OUTPUT_DIR {rag_prompt_dir} --MODE generate --MODEL llama --VID_NUM {selected_videos_num} --TAGS_NUM {tag}"
|
| 38 |
+
result = os.system(command) # Run the command
|
| 39 |
+
if result == 0:
|
| 40 |
+
print(f"Generated RAG prompt for: {prompt[:50]} -> Saved to {rag_prompt_file}")
|
| 41 |
+
else:
|
| 42 |
+
print(f"Error generating RAG prompt for: {prompt}")
|
| 43 |
+
continue
|
| 44 |
+
|
| 45 |
+
# Process all RAG prompt files
|
| 46 |
+
# Run inference
|
| 47 |
+
command = f"python {script_file} --INPUT_DIR {rag_prompt_dir} --OUTPUT_DIR {output_dir} --MODE infer --MODEL llama --VID_NUM {selected_videos_num} --TAGS_NUM {tag}"
|
| 48 |
+
result = os.system(command) # Run the command
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
print("All prompts have been processed and saved.")
|