ChatWebPage / app.py
hersia's picture
Duplicate from jackculpan/chatwebpage.com
9933e0f
raw
history blame contribute delete
No virus
1.84 kB
import os
import openai
import gradio as gr
import requests
from bs4 import BeautifulSoup
from conversation import Conversation
try:
from dotenv import load_dotenv
load_dotenv()
except ImportError:
pass # In production, python-dotenv may not be installed
openai.api_key = os.getenv("OPEN_API_KEY")
with gr.Blocks(css="footer {visibility: hidden}", title="chatWEBPAGE") as demo:
conversation = Conversation()
gr.Markdown("Enter your website url, then ask the AI a question.")
with gr.Row():
with gr.Column(scale=2):
url = gr.Textbox(label="1. Enter a webpage URL to chat about")
url.change(fn=conversation.get_data, inputs=url)
with gr.Column(scale=3):
gr.Examples([
"https://www.bbc.com/news/business-64937251",
"https://www.ycombinator.com/",
"https://news.ycombinator.com/",
"https://www.producthunt.com/posts/chatwebpage"], inputs=[url])
chatbot = gr.Chatbot().style(height=150)
msg = gr.Textbox(label="2. Chat with AI about the webpage")
msg.submit(conversation.user, [msg, chatbot], [msg, chatbot]).success(conversation.bot, chatbot, chatbot)
gr.Examples(["Please summarise the webpage", "What is the tone of the webpage?", "Tell me your favorite part of the webpage"], inputs=[msg])
with gr.Row():
with gr.Column(scale=2):
clear_button = gr.Button("Clear")
clear_button.click(lambda: None, None, chatbot)
with gr.Column(scale=4):
submit_button = gr.Button("Submit")
submit_button.click(conversation.user, [msg, chatbot], [msg, chatbot]).success(
conversation.bot, chatbot, chatbot
)
if __name__ == "__main__":
# demo.queue()
demo.launch()