Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
from agent import start_scraping, display_csv, generate_rss_feed, chat_interface
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def create_interface():
|
|
|
6 |
with gr.Blocks() as demo:
|
7 |
with gr.Row():
|
8 |
with gr.Column():
|
@@ -22,8 +30,25 @@ def create_interface():
|
|
22 |
chat_history = gr.Chatbot(label="Chat History")
|
23 |
response_box = gr.Textbox(label="Response")
|
24 |
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
# Add a button to display the RSS feed for a selected URL
|
29 |
with gr.Row():
|
@@ -31,7 +56,14 @@ def create_interface():
|
|
31 |
rss_button = gr.Button("Generate RSS Feed")
|
32 |
rss_output = gr.Textbox(label="RSS Feed Output", interactive=False)
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
return demo
|
37 |
|
|
|
1 |
import gradio as gr
|
2 |
from agent import start_scraping, display_csv, generate_rss_feed, chat_interface
|
3 |
|
4 |
+
def validate_input(values):
|
5 |
+
"""Validate user input"""
|
6 |
+
if not values["storage_location"]:
|
7 |
+
raise ValueError("Storage location cannot be empty")
|
8 |
+
if not values["urls"]:
|
9 |
+
raise ValueError("URLs cannot be empty")
|
10 |
+
return values
|
11 |
+
|
12 |
def create_interface():
|
13 |
+
"""Create Gradio interface"""
|
14 |
with gr.Blocks() as demo:
|
15 |
with gr.Row():
|
16 |
with gr.Column():
|
|
|
30 |
chat_history = gr.Chatbot(label="Chat History")
|
31 |
response_box = gr.Textbox(label="Response")
|
32 |
|
33 |
+
def start_scraping_callback(values):
|
34 |
+
"""Start scraping callback"""
|
35 |
+
try:
|
36 |
+
validated_values = validate_input(values)
|
37 |
+
start_scraping(validated_values["storage_location"], validated_values["urls"], validated_values["scrape_interval"], validated_values["content_type"])
|
38 |
+
display_csv(validated_values["storage_location"])
|
39 |
+
except Exception as e:
|
40 |
+
print(f"Error: {str(e)}")
|
41 |
+
|
42 |
+
start_button.click(start_scraping_callback, inputs=[storage_location, urls, scrape_interval, content_type], outputs=csv_output)
|
43 |
+
|
44 |
+
def chat_interface_callback(values):
|
45 |
+
"""Chat interface callback"""
|
46 |
+
try:
|
47 |
+
chat_interface(values["message"], chat_history, system_message, max_tokens, temperature, top_p, storage_location, urls, scrape_interval, content_type)
|
48 |
+
except Exception as e:
|
49 |
+
print(f"Error: {str(e)}")
|
50 |
+
|
51 |
+
message.submit(chat_interface_callback, inputs=[message, chat_history, system_message, max_tokens, temperature, top_p, storage_location, urls, scrape_interval, content_type], outputs=[chat_history, response_box])
|
52 |
|
53 |
# Add a button to display the RSS feed for a selected URL
|
54 |
with gr.Row():
|
|
|
56 |
rss_button = gr.Button("Generate RSS Feed")
|
57 |
rss_output = gr.Textbox(label="RSS Feed Output", interactive=False)
|
58 |
|
59 |
+
def generate_rss_feed_callback(values):
|
60 |
+
"""Generate RSS feed callback"""
|
61 |
+
try:
|
62 |
+
generate_rss_feed(values["selected_url"])
|
63 |
+
except Exception as e:
|
64 |
+
print(f"Error: {str(e)}")
|
65 |
+
|
66 |
+
rss_button.click(generate_rss_feed_callback, inputs=[selected_url], outputs=rss_output)
|
67 |
|
68 |
return demo
|
69 |
|