Spaces:
Runtime error
Runtime error
acecalisto3
commited on
Commit
•
b613fcb
1
Parent(s):
b723646
Update app.py
Browse files
app.py
CHANGED
@@ -63,8 +63,8 @@ def monitor_urls(storage_location, urls, scrape_interval, content_type, stop_scr
|
|
63 |
except Exception as e:
|
64 |
logging.error(f"Error starting ChromeDriver: {e}")
|
65 |
|
66 |
-
def start_scraping(storage_location, urls, scrape_interval, content_type
|
67 |
-
global CURRENT_TASK, HISTORY
|
68 |
|
69 |
CURRENT_TASK = f"Monitoring URLs: {', '.join(urls)}"
|
70 |
HISTORY.append(f"Task started: {CURRENT_TASK}")
|
@@ -94,13 +94,14 @@ def start_scraping(storage_location, urls, scrape_interval, content_type, stop_s
|
|
94 |
HISTORY.append(f"Error accessing {url}: {e}")
|
95 |
|
96 |
# Start a new thread for monitoring URLs
|
97 |
-
threading.Thread(target=monitor_urls, args=(storage_location,
|
98 |
|
99 |
return f"Started scraping {', '.join(urls)} every {scrape_interval} minutes."
|
100 |
|
101 |
# Define a function to stop scraping
|
102 |
-
def stop_scraping(
|
103 |
-
|
|
|
104 |
return "Scraping stopped."
|
105 |
|
106 |
# Define a function to update model config
|
@@ -126,7 +127,7 @@ def create_interface():
|
|
126 |
start_button = gr.Button("Start Scraping")
|
127 |
stop_button = gr.Button("Stop Scraping")
|
128 |
csv_output = gr.Textbox(label="CSV Output", interactive=False)
|
129 |
-
|
130 |
model_name_input = gr.Textbox(value="default_model", label="Model Name")
|
131 |
gpu_layers_input = gr.Slider(minimum=0, maximum=8, value=2, step=1, label="GPU Layers")
|
132 |
|
@@ -134,13 +135,15 @@ def create_interface():
|
|
134 |
chat_history = gr.Chatbot(label="Chat History")
|
135 |
response_box = gr.Textbox(label="Response")
|
136 |
|
137 |
-
|
138 |
start_button.click(
|
139 |
fn=start_scraping,
|
140 |
-
inputs=[storage_location, urls, scrape_interval, content_type
|
141 |
outputs=csv_output
|
142 |
)
|
143 |
-
stop_button.click(stop_scraping,
|
|
|
|
|
144 |
message.submit(chat_interface, inputs=[message, chat_history, system_message, max_tokens, temperature, top_p], outputs=[chat_history, response_box])
|
145 |
|
146 |
# Add a button to display the CSV content for a selected URL
|
|
|
63 |
except Exception as e:
|
64 |
logging.error(f"Error starting ChromeDriver: {e}")
|
65 |
|
66 |
+
def start_scraping(storage_location, urls, scrape_interval, content_type):
|
67 |
+
global CURRENT_TASK, HISTORY, STOP_THREADS
|
68 |
|
69 |
CURRENT_TASK = f"Monitoring URLs: {', '.join(urls)}"
|
70 |
HISTORY.append(f"Task started: {CURRENT_TASK}")
|
|
|
94 |
HISTORY.append(f"Error accessing {url}: {e}")
|
95 |
|
96 |
# Start a new thread for monitoring URLs
|
97 |
+
threading.Thread(target=monitor_urls, args=(storage_location, [url], scrape_interval, content_type, [STOP_THREADS])).start()
|
98 |
|
99 |
return f"Started scraping {', '.join(urls)} every {scrape_interval} minutes."
|
100 |
|
101 |
# Define a function to stop scraping
|
102 |
+
def stop_scraping():
|
103 |
+
global STOP_THREADS
|
104 |
+
STOP_THREADS = True
|
105 |
return "Scraping stopped."
|
106 |
|
107 |
# Define a function to update model config
|
|
|
127 |
start_button = gr.Button("Start Scraping")
|
128 |
stop_button = gr.Button("Stop Scraping")
|
129 |
csv_output = gr.Textbox(label="CSV Output", interactive=False)
|
130 |
+
|
131 |
model_name_input = gr.Textbox(value="default_model", label="Model Name")
|
132 |
gpu_layers_input = gr.Slider(minimum=0, maximum=8, value=2, step=1, label="GPU Layers")
|
133 |
|
|
|
135 |
chat_history = gr.Chatbot(label="Chat History")
|
136 |
response_box = gr.Textbox(label="Response")
|
137 |
|
138 |
+
# Connect buttons to their respective functions
|
139 |
start_button.click(
|
140 |
fn=start_scraping,
|
141 |
+
inputs=[storage_location, urls, scrape_interval, content_type],
|
142 |
outputs=csv_output
|
143 |
)
|
144 |
+
stop_button.click(stop_scraping, outputs=csv_output)
|
145 |
+
|
146 |
+
# Connect message submission to the chat interface
|
147 |
message.submit(chat_interface, inputs=[message, chat_history, system_message, max_tokens, temperature, top_p], outputs=[chat_history, response_box])
|
148 |
|
149 |
# Add a button to display the CSV content for a selected URL
|