File size: 1,842 Bytes
9933e0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
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
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()