Spaces:
Running
Running
File size: 1,912 Bytes
28df3d5 e1ec379 951ed07 e1ec379 28df3d5 e1ec379 04bb0cc 951ed07 28df3d5 4a8fb2a 951ed07 4a8fb2a 1445253 4a8fb2a 47263a6 ae66542 28df3d5 ec06302 28df3d5 db0da6b 308568a 18e7ac6 28df3d5 b16e60c 04f6f00 b16e60c db0da6b b98125f b251756 20b2cf1 9d3f8b4 1117379 | 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
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()
|