acecalisto3 commited on
Commit
bdc2e36
1 Parent(s): 51f3351

Update agent.py

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