chatwebpage.com / app.py
jackculpan's picture
;arger chat
ec06302
import os
import openai
import gradio as gr
from conversation import Conversation
try:
from dotenv import load_dotenv
load_dotenv()
except ImportError:
pass # In production, python-dotenv may not be installed
with gr.Blocks(css="footer {visibility: hidden}", title="ChatWebpage.com") 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://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)
with gr.Row():
with gr.Column(scale=4):
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.Column(scale=4):
model = gr.Radio(["GPT-3.5", "GPT-4"], value="gpt-3.5", label="3. Which AI model?")
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(concurrency_count=4)
demo.launch()