Spaces:
Runtime error
Runtime error
acecalisto3
commited on
Update agent.py
Browse files
agent.py
CHANGED
@@ -53,7 +53,7 @@ def monitor_urls(storage_location, urls, scrape_interval, content_type):
|
|
53 |
else:
|
54 |
current_content = driver.page_source
|
55 |
current_hash = hashlib.md5(str(current_content).encode('utf-8')).hexdigest()
|
56 |
-
if current_hash
|
57 |
previous_hashes[url] = current_hash
|
58 |
date_time_str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
59 |
HISTORY.append(f"Change detected at {url} on {date_time_str}")
|
@@ -150,4 +150,44 @@ def generate_rss_feed(url):
|
|
150 |
def chat_interface(message, history, system_message, max_tokens, temperature, top_p, storage_location, urls, scrape_interval, content_type):
|
151 |
response = respond(message, history, system_message, max_tokens, temperature, top_p)
|
152 |
history.append((message, response))
|
153 |
-
return history, response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
else:
|
54 |
current_content = driver.page_source
|
55 |
current_hash = hashlib.md5(str(current_content).encode('utf-8')).hexdigest()
|
56 |
+
if current_hash!= previous_hashes[url]:
|
57 |
previous_hashes[url] = current_hash
|
58 |
date_time_str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
59 |
HISTORY.append(f"Change detected at {url} on {date_time_str}")
|
|
|
150 |
def chat_interface(message, history, system_message, max_tokens, temperature, top_p, storage_location, urls, scrape_interval, content_type):
|
151 |
response = respond(message, history, system_message, max_tokens, temperature, top_p)
|
152 |
history.append((message, response))
|
153 |
+
return history, response
|
154 |
+
|
155 |
+
if __name__ == "__main__":
|
156 |
+
# Define the Gradio interface
|
157 |
+
import gradio as gr
|
158 |
+
|
159 |
+
def create_interface():
|
160 |
+
with gr.Blocks() as demo:
|
161 |
+
with gr.Row():
|
162 |
+
with gr.Column():
|
163 |
+
message = gr.Textbox(label="Message")
|
164 |
+
system_message = gr.Textbox(value="You are a helpful assistant.", label="System message")
|
165 |
+
max_tokens = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
|
166 |
+
temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
|
167 |
+
top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
168 |
+
storage_location = gr.Textbox(value="scraped_data", label="Storage Location")
|
169 |
+
urls = gr.Textbox(label="URLs (comma separated)")
|
170 |
+
scrape_interval = gr.Slider(minimum=1, maximum=60, value=5, step=1, label="Scrape Interval (minutes)")
|
171 |
+
content_type = gr.Radio(choices=["text", "media", "both"], value="text", label="Content Type")
|
172 |
+
start_button = gr.Button("Start Scraping")
|
173 |
+
csv_output = gr.Textbox(label="CSV Output", interactive=False)
|
174 |
+
|
175 |
+
with gr.Column():
|
176 |
+
chat_history = gr.Chatbot(label="Chat History")
|
177 |
+
response_box = gr.Textbox(label="Response")
|
178 |
+
|
179 |
+
start_button.click(start_scraping, inputs=[storage_location, urls, scrape_interval, content_type], outputs=csv_output)
|
180 |
+
message.submit(chat_interface, inputs=[message, chat_history, system_message, max_tokens, temperature, top_p, storage_location, urls, scrape_interval, content_type], outputs=[chat_history, response_box])
|
181 |
+
|
182 |
+
# Add a button to display the RSS feed for a selected URL
|
183 |
+
with gr.Row():
|
184 |
+
selected_url = gr.Textbox(label="Select URL for RSS Feed")
|
185 |
+
rss_button = gr.Button("Generate RSS Feed")
|
186 |
+
rss_output = gr.Textbox(label="RSS Feed Output", interactive=False)
|
187 |
+
|
188 |
+
rss_button.click(generate_rss_feed, inputs=[selected_url], outputs=rss_output)
|
189 |
+
|
190 |
+
return demo
|
191 |
+
|
192 |
+
demo = create_interface()
|
193 |
+
demo.launch()
|