In today’s digital landscape, navigating through the vast expanse of online information can be overwhelming. Researchers, students, and professionals alike often find themselves sifting through numerous web pages to extract relevant insights. However, this process can be time-consuming and inefficient.
Recognizing the need for a more streamlined approach to web exploration and note-taking, we introduce WebBrief — an innovative tool powered by Lyzr SDK. WebBrief revolutionizes the way users interact with web content, offering a seamless solution for extracting valuable information and generating concise notes.
Why use Lyzr SDK’s?
With Lyzr SDKs, crafting your own GenAI application is a breeze, requiring only a few lines of code to get up and running swiftly.
Lets get Started!
Create a new file app.py and use that
Setting Up Dependencies:
Before delving into the intricacies of WebBrief’s functionality, it’s essential to ensure that all necessary dependencies are in place.
import os
os.system("playwright install")
from PIL import Image
import streamlit as st
from lyzr import ChatBot
import openai
from lyzr import VoiceBot
The code you’ve provided imports several libraries and installs Playwright, a tool for automating browsers. Then, it imports PIL (Python Imaging Library) for image processing, Streamlit for creating interactive web apps, and the Lyzr library for integrating a chatbot. Additionally, it imports OpenAI for natural language processing tasks.
os.environ["OPENAI_API_KEY"] = st.secrets["apikey"]
vb = VoiceBot(api_key= os.environ["OPENAI_API_KEY"])
This code sets the OpenAI API key by accessing it from the Streamlit secrets configuration. Then, it initializes a VoiceBot object from the Lyzr library, utilizing the OpenAI API key for natural language processing tasks, such as generating responses or understanding user inputs, likely integrating note generation capabilities into the chatbot powered by OpenAI’s technology.
Styling the App:
Define custom CSS styles to enhance the appearance of the web app.
def style_app():
# CSS styles
st.markdown("""
<style>
/* CSS styles here */
</style>
""", unsafe_allow_html=True)
style_app()
# Define function to initialize chatbot
def initialize_chatbot(url):
# Replace these parameters with your actual Weaviate Vector Store parameters
vector_store_params = {
"vector_store_type": "WeaviateVectorStore",
"url": "https://sample.network",
"api_key": "your_api_key",
"index_name": "Akshay"
}
# Initialize the Webpage Chatbot with the provided URL
return ChatBot.webpage_chat(
url=url,
vector_store_params=vector_store_params
)
This Python function initializes a chatbot intended for webpage interaction using the Lyzr library. It requires a URL parameter indicating the webpage where the chatbot will be integrated. Additionally, it sets up parameters for a Weaviate Vector Store, likely employed for semantic understanding and response generation. The function returns an instance of the initialized chatbot, configured with the provided URL and vector store parameters.
# Main function to run the Streamlit app
def main():
# User input for URL
url = st.text_input("Enter the URL of the webpage:")
# Check if URL is provided
if url:
# Initialize the chatbot with the provided URL
chatbot = initialize_chatbot(url)
# Pre-defined prompts
prompts = [
"What is the summary of this page?",
"Can you explain the history of this topic?",
"Who are the notable figures related to this topic?",
"What are the controversies surrounding this topic?"
]
# Display pre-defined prompts as buttons
col1, col2 = st.columns(2)
for i, prompt in enumerate(prompts):
if i % 2 == 0:
button = col1.button(prompt, key=f"button_{i}")
else:
button = col2.button(prompt, key=f"button_{i}")
# Check if button is clicked
if button:
# Chat with the chatbot
response = chatbot.chat(prompt)
# Display chatbot's response
st.write("Chatbot's Response:")
st.write(response.response)
user_question = st.text_input("Enter the query to generate notes :")
# Chat with the chatbot if user provides a question
# Chat with the chatbot if user provides a question
if user_question:
response = chatbot.chat(user_question)
notes = vb.text_to_notes(response.response)
st.write(notes)
This Python script creates a user interface for interacting with a chatbot, built using Streamlit (st). Initially, users input a URL, which initializes the chatbot. Pre-defined prompts covering various aspects of the webpage are displayed as buttons. When clicked, these prompts trigger interactions with the chatbot, providing responses relevant to the selected prompt.
Additionally, users can input questions directly. These queries are sent to the chatbot, and the responses are processed to generate notes using a function called vb.text_to_notes().
# Run the Streamlit app
if __name__ == "__main__":
main()
The if name == "main": block ensures that the Streamlit app defined in the main() function is executed only when the script is run directly. This approach promotes modularity, allowing the script to be imported into other modules without automatically triggering the execution of the Streamlit app.
WebBrief represents a significant advancement in web exploration and note-taking, offering users a seamless and efficient means of extracting and organizing information from web pages. By leveraging Lyzr SDK and integrating powerful conversational AI capabilities, WebBrief empowers users to navigate the digital landscape with confidence and ease.
Watch the tutorial : https://www.youtube.com/watch?v=mZeklBWyMmY
With Lyzr SDK’s, the journey from concept to creation is streamlined, empowering developers to craft captivating applications with ease. Imagine the possibilities — whether it’s the creation of a Chatbot for website or the exploration of other innovative projects. The possibilities are endless, and with Lyzr SDK’s, the future of Gen-AI applications is limited only by imagination.
References
Lyzr Website: Lyzr
Book a Demo: Demo
Lyzr Community Channels: Discord
Slack : Slack
Top comments (0)