Spaces:
Running
Running
acecalisto3
commited on
Commit
•
51f3351
1
Parent(s):
5270bb9
Update prompts.py
Browse files- prompts.py +174 -5
prompts.py
CHANGED
@@ -14,11 +14,180 @@ BAD ANSWER EXAMPLE
|
|
14 |
- You can write code referring these pages.
|
15 |
- Following page will be helpful.
|
16 |
GOOD ANSWER EXAMPLE
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
"""
|
23 |
AI_SYSTEM_PROMPT = """
|
24 |
You are an expert Prompt Engineer who specializes in coding AI Agent System Prompts. Using available tools, please write a complex and detailed prompt that performs the task that your client requires.
|
|
|
14 |
- You can write code referring these pages.
|
15 |
- Following page will be helpful.
|
16 |
GOOD ANSWER EXAMPLE
|
17 |
+
urls = [
|
18 |
+
"https://twitter.com/wlcscrdp",
|
19 |
+
"https://www.facebook.com/aurorareddevils/",
|
20 |
+
"https://www.facebook.com/brightpanthers/",
|
21 |
+
"https://www.facebook.com/carrollcountychamberin/",
|
22 |
+
"https://www.facebook.com/Culver.Cavs.MHS",
|
23 |
+
"https://www.facebook.com/culver.elementary.school",
|
24 |
+
"https://www.facebook.com/CulverCommunitySchools",
|
25 |
+
"https://www.facebook.com/DillsboroBulldogs/",
|
26 |
+
"https://www.facebook.com/ECMSTROJANS",
|
27 |
+
"https://www.facebook.com/enjoywhitecountyIN/",
|
28 |
+
"https://www.facebook.com/farmersvilleelementary",
|
29 |
+
"https://www.facebook.com/groups/SDMSparents",
|
30 |
+
"https://www.facebook.com/jghsart/",
|
31 |
+
"https://www.facebook.com/jgmusicdept",
|
32 |
+
"https://www.facebook.com/John-Glenn-Education-Foundation-208326199636364/",
|
33 |
+
"https://www.facebook.com/John-Glenn-High-School-1102148953201006/",
|
34 |
+
"https://www.facebook.com/John-Glenn-Theatre-Company-383638295064502/",
|
35 |
+
"https://www.facebook.com/JohnGlennFalconsAthletics",
|
36 |
+
"https://www.facebook.com/KIRPC-Head-Start-1485812354989001",
|
37 |
+
"https://www.facebook.com/KIRPC1",
|
38 |
+
"https://www.facebook.com/LHNEeagles",
|
39 |
+
"https://www.facebook.com/LuceElementarySchool/",
|
40 |
+
"https://www.facebook.com/marrselementary",
|
41 |
+
"https://www.facebook.com/messhiners/",
|
42 |
+
"https://www.facebook.com/monticellocitypool",
|
43 |
+
"https://www.facebook.com/monticelloinwastewater/",
|
44 |
+
"https://www.facebook.com/MooresHillBobcats/",
|
45 |
+
"https://www.facebook.com/msdmv",
|
46 |
+
"https://www.facebook.com/msdnorthposey",
|
47 |
+
"https://www.facebook.com/MUTPL/",
|
48 |
+
"https://www.facebook.com/MVJHS/",
|
49 |
+
"https://www.facebook.com/mvshs",
|
50 |
+
"https://www.facebook.com/njspjrsrhighschool?mibextid=b06tZ0",
|
51 |
+
"https://www.facebook.com/NorthElementaryStars/",
|
52 |
+
"https://www.facebook.com/NorthLibertyElementary/",
|
53 |
+
"https://www.facebook.com/northposey/",
|
54 |
+
"https://www.facebook.com/northposeyhs/",
|
55 |
+
"https://www.facebook.com/NPJuniorHigh",
|
56 |
+
"https://www.facebook.com/Prairie-Heights-Elementary-659322230934707/",
|
57 |
+
"https://www.facebook.com/Prairie-Heights-High-School-2027713067459043/",
|
58 |
+
"https://www.facebook.com/PrairieHeightsPanthers/",
|
59 |
+
"https://www.facebook.com/profile.php?id=100057030237096",
|
60 |
+
"https://www.facebook.com/profile.php?id=100057451179651",
|
61 |
+
"https://www.facebook.com/profile.php?id=100063463513451",
|
62 |
+
"https://www.facebook.com/profile.php?id=100063612319256",
|
63 |
+
"https://www.facebook.com/profile.php?id=100064532596422",
|
64 |
+
"https://www.facebook.com/profile.php?id=100067180226810",
|
65 |
+
"https://www.facebook.com/profile.php?id=61563484312348",
|
66 |
+
"https://www.facebook.com/PTOSWES/",
|
67 |
+
"https://www.facebook.com/RandolphSouthern/",
|
68 |
+
"https://www.facebook.com/RochesterMiddleSchool",
|
69 |
+
"https://www.facebook.com/RochesterZebraNewTechHigh",
|
70 |
+
"https://www.facebook.com/rockportelementarysouthspencer/",
|
71 |
+
"https://www.facebook.com/satellitesathletics/",
|
72 |
+
"https://www.facebook.com/seymourcommunityschools/",
|
73 |
+
"https://www.facebook.com/SeymourHighSchool/",
|
74 |
+
"https://www.facebook.com/SouthDearbornHighSchool/",
|
75 |
+
"https://www.facebook.com/southarbornschools/",
|
76 |
+
"https://www.facebook.com/SouthDearbornSquires/",
|
77 |
+
"https://www.facebook.com/southspencerhighschool",
|
78 |
+
"https://www.facebook.com/southspencermiddleschool/",
|
79 |
+
"https://www.facebook.com/SouthSpencerSchools",
|
80 |
+
"https://www.facebook.com/SouthTerracePanthers/",
|
81 |
+
"https://www.facebook.com/sunmantigers/",
|
82 |
+
"https://www.facebook.com/SWShelbySpartan/",
|
83 |
+
"https://www.facebook.com/TallTimbersMarina",
|
84 |
+
"https://www.facebook.com/WabashValleyESC/",
|
85 |
+
"https://www.facebook.com/Walkerton-Elementary-School-283088605088622/",
|
86 |
+
"https://www.facebook.com/westcentralcte/",
|
87 |
+
"https://www.facebook.com/westelementary",
|
88 |
+
"https://www.facebook.com/wlcscrdp",
|
89 |
+
"https://www.instagram.com/mutpl/",
|
90 |
+
"https://www.instagram.com/northposeyhsathletics",
|
91 |
+
"https://www.instagram.com/rchsprincipalcook/",
|
92 |
+
"https://www.instagram.com/southdearbornhighschool/",
|
93 |
+
"https://www.instagram.com/southdearbornschools/",
|
94 |
+
"https://www.instagram.com/westcentralcte/",
|
95 |
+
"https://www.tiktok.com/@mutplteen"
|
96 |
+
]
|
97 |
+
|
98 |
+
|
99 |
+
# Configure logging
|
100 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
101 |
+
|
102 |
+
# Define constants
|
103 |
+
DATE_TIME_STR = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
104 |
+
PURPOSE = f"You go to Culvers sites, you continuously seek changes on them since your last observation. Anything new that gets logged and dumped into csv, stored in your log folder at user/app/scraped_data."
|
105 |
+
HISTORY = []
|
106 |
+
CURRENT_TASK = None
|
107 |
+
DEFAULT_FILE_PATH = "user/app/scraped_data/culver/culvers_changes.csv"
|
108 |
+
|
109 |
+
# Ensure the directory exists
|
110 |
+
os.makedirs(os.path.dirname(DEFAULT_FILE_PATH), exist_ok=True)
|
111 |
+
|
112 |
+
# Function to monitor URLs for changes
|
113 |
+
def monitor_urls(storage_location, urls, scrape_interval, content_type):
|
114 |
+
global HISTORY
|
115 |
+
previous_hashes = [""] * len(urls)
|
116 |
+
|
117 |
+
try:
|
118 |
+
with webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=Options()) as driver:
|
119 |
+
while True:
|
120 |
+
for i, url in enumerate(urls):
|
121 |
+
try:
|
122 |
+
driver.get(url)
|
123 |
+
time.sleep(2) # Wait for the page to load
|
124 |
+
if content_type == "text":
|
125 |
+
current_content = driver.page_source
|
126 |
+
elif content_type == "media":
|
127 |
+
current_content = driver.find_elements_by_tag_name("img")
|
128 |
+
else:
|
129 |
+
current_content = driver.page_source
|
130 |
+
current_hash = hashlib.md5(str(current_content).encode('utf-8')).hexdigest()
|
131 |
+
if current_hash != previous_hashes[i]:
|
132 |
+
previous_hashes[i] = current_hash
|
133 |
+
date_time_str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
134 |
+
HISTORY.append(f"Change detected at {url} on {date_time_str}")
|
135 |
+
with open(storage_location, "a", newline="") as csvfile:
|
136 |
+
csv_writer = csv.DictWriter(csvfile, fieldnames=["date", "time", "url", "change"])
|
137 |
+
csv_writer.writerow({"date": date_time_str.split()[0], "time": date_time_str.split()[1], "url": url, "change": "Content changed"})
|
138 |
+
logging.info(f"Change detected at {url} on {date_time_str}")
|
139 |
+
except Exception as e:
|
140 |
+
logging.error(f"Error accessing {url}: {e}")
|
141 |
+
time.sleep(scrape_interval * 60) # Check every scrape_interval minutes
|
142 |
+
except Exception as e:
|
143 |
+
logging.error(f"Error starting ChromeDriver: {e}")
|
144 |
+
|
145 |
+
# Define main function to handle user input
|
146 |
+
def handle_input(storage_location, urls, scrape_interval, content_type):
|
147 |
+
global CURRENT_TASK, HISTORY
|
148 |
+
|
149 |
+
CURRENT_TASK = f"Monitoring URLs: {', '.join(urls)}"
|
150 |
+
HISTORY.append(f"Task started: {CURRENT_TASK}")
|
151 |
+
monitor_urls(storage_location, urls, scrape_interval, content_type)
|
152 |
+
return TASK_PROMPT.format(task=CURRENT_TASK, history="\n".join(map(str, HISTORY)))
|
153 |
+
|
154 |
+
# Load custom prompts
|
155 |
+
try:
|
156 |
+
with open("custom_prompts.yaml", "r") as fp:
|
157 |
+
custom_prompts = yaml.safe_load(fp)
|
158 |
+
except FileNotFoundError:
|
159 |
+
custom_prompts = {"WEB_DEV": "", "AI_SYSTEM_PROMPT": "", "PYTHON_CODE_DEV": "", "CODE_GENERATION": "", "CODE_INTERPRETATION": "", "CODE_TRANSLATION": "", "CODE_IMPLEMENTATION": ""}
|
160 |
+
|
161 |
+
# Define agents
|
162 |
+
AGENTS = ["WEB_DEV", "AI_SYSTEM_PROMPT", "PYTHON_CODE_DEV", "CODE_GENERATION", "CODE_INTERPRETATION", "CODE_TRANSLATION", "CODE_IMPLEMENTATION"]
|
163 |
+
|
164 |
+
# Define the Mistral inference client
|
165 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
166 |
+
|
167 |
+
# Define the chat response function
|
168 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
169 |
+
return generate(message, history, system_message, max_tokens, temperature, top_p)
|
170 |
+
|
171 |
+
# Function to start scraping
|
172 |
+
def start_scraping(storage_location, url1, url2, url3, url4, url5, url6, url7, url8, url9, url10, scrape_interval, content_type):
|
173 |
+
urls = [url for url in [url1, url2, url3, url4, url5, url6, url7, url8, url9, url10] if url]
|
174 |
+
handle_input(storage_location, urls, scrape_interval, content_type)
|
175 |
+
return f"Started scraping {', '.join(urls)} every {scrape_interval} minutes."
|
176 |
+
|
177 |
+
# Function to display CSV content
|
178 |
+
def display_csv(storage_location):
|
179 |
+
if os.path.exists(storage_location):
|
180 |
+
with open(storage_location, "r") as file:
|
181 |
+
return file.read()
|
182 |
+
else:
|
183 |
+
return "No data available."
|
184 |
+
|
185 |
+
# Create Gradio interface
|
186 |
+
def chat_interface(message, system_message, max_tokens, temperature, top_p, storage_location, url1, url2, url3, url4, url5, url6, url7, url8, url9, url10, scrape_interval, content_type):
|
187 |
+
global HISTORY
|
188 |
+
response = respond(message, HISTORY, system_message, max_tokens, temperature, top_p)
|
189 |
+
HISTORY.append((message, response))
|
190 |
+
return HISTORY, ""
|
191 |
"""
|
192 |
AI_SYSTEM_PROMPT = """
|
193 |
You are an expert Prompt Engineer who specializes in coding AI Agent System Prompts. Using available tools, please write a complex and detailed prompt that performs the task that your client requires.
|