Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,74 +1,53 @@
|
|
1 |
-
import
|
2 |
from agent import start_scraping, display_csv, generate_rss_feed, chat_interface
|
|
|
3 |
|
4 |
-
def
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
return
|
11 |
-
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
except Exception as e:
|
51 |
-
print(f"Error: {str(e)}")
|
52 |
-
|
53 |
-
message.submit(chat_interface_callback, inputs=[message, chat_history, system_message, max_tokens, temperature, top_p, storage_location, urls, scrape_interval, content_type, selector], outputs=[chat_history, response_box])
|
54 |
-
|
55 |
-
# Add a button to display the RSS feed for a selected URL
|
56 |
-
with gr.Row():
|
57 |
-
selected_url = gr.Textbox(label="Select URL for RSS Feed")
|
58 |
-
rss_button = gr.Button("Generate RSS Feed")
|
59 |
-
rss_output = gr.Textbox(label="RSS Feed Output", interactive=False)
|
60 |
-
|
61 |
-
def generate_rss_feed_callback(values):
|
62 |
-
"""Generate RSS feed callback"""
|
63 |
-
try:
|
64 |
-
rss_output.value = generate_rss_feed(storage_location, values["selected_url"])
|
65 |
-
except Exception as e:
|
66 |
-
print(f"Error: {str(e)}")
|
67 |
-
|
68 |
-
rss_button.click(generate_rss_feed_callback, inputs=[selected_url], outputs=rss_output)
|
69 |
-
|
70 |
-
return demo
|
71 |
|
72 |
if __name__ == "__main__":
|
73 |
-
|
74 |
-
demo.launch()
|
|
|
1 |
+
import os
|
2 |
from agent import start_scraping, display_csv, generate_rss_feed, chat_interface
|
3 |
+
import gradio as gr
|
4 |
|
5 |
+
def chatbot_interface(message, history, system_message, max_tokens, temperature, top_p, storage_location, urls, scrape_interval, content_type, selector):
|
6 |
+
history, response = chat_interface(message, history, system_message, max_tokens, temperature, top_p, storage_location, urls, scrape_interval, content_type, selector)
|
7 |
+
return history, response
|
8 |
+
|
9 |
+
def generate_rss(storage_location, url):
|
10 |
+
feed_entries = generate_rss_feed(storage_location, url)
|
11 |
+
return feedparser.FeedParserDict(feed_entries)
|
12 |
+
|
13 |
+
def main():
|
14 |
+
storage_location = "scraped_data"
|
15 |
+
urls = ["https://www.culvers.com/"]
|
16 |
+
scrape_interval = 5
|
17 |
+
content_type = "text"
|
18 |
+
selector = ""
|
19 |
+
|
20 |
+
chatbot_input = gr.inputs.Textbox(lines=5, label="Chatbot Input")
|
21 |
+
history_output = gr.outputs.Textbox(label="History")
|
22 |
+
response_output = gr.outputs.Textbox(label="Response")
|
23 |
+
|
24 |
+
csv_input = gr.inputs.Textbox(lines=1, label="CSV Input URL")
|
25 |
+
csv_output = gr.outputs.Textbox(label="CSV Output")
|
26 |
+
|
27 |
+
rss_input = gr.inputs.Textbox(lines=1, label="RSS Input URL")
|
28 |
+
rss_output = gr.outputs.HTML(label="RSS Output")
|
29 |
+
|
30 |
+
chatbot_interface = gr.Interface(
|
31 |
+
chatbot_interface,
|
32 |
+
[chatbot_input, history_output, system_message, max_tokens, temperature, top_p, storage_location, urls, scrape_interval, content_type, selector],
|
33 |
+
[history_output, response_output]
|
34 |
+
)
|
35 |
+
|
36 |
+
csv_interface = gr.Interface(
|
37 |
+
lambda url: display_csv(storage_location, url),
|
38 |
+
[csv_input],
|
39 |
+
[csv_output]
|
40 |
+
)
|
41 |
+
|
42 |
+
rss_interface = gr.Interface(
|
43 |
+
generate_rss,
|
44 |
+
[rss_input, storage_location],
|
45 |
+
[rss_output]
|
46 |
+
)
|
47 |
+
|
48 |
+
chatbot_interface.launch()
|
49 |
+
csv_interface.launch()
|
50 |
+
rss_interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
+
main()
|
|