DEV Community

harshit-lyzr
harshit-lyzr

Posted on

Enhance Your Review Management with AI Review Aggregator and Summarizer

In today’s digital marketplace, customer reviews play a pivotal role in shaping consumer decisions and brand reputation. Managing and summarizing these reviews effectively can provide invaluable insights for businesses. Introducing the AI Review Aggregator and Summarizer, an innovative application designed to harness the power of Lyzr Automata and Streamlit, making review analysis and summarization more efficient and insightful.

What is AI Review Aggregator and Summarizer?
The AI Review Aggregator and Summarizer is a cutting-edge app that uses advanced AI models to perform sentiment analysis, aggregate reviews, and provide comprehensive summaries. This tool is essential for businesses seeking to streamline their review management process and gain actionable insights from customer feedback.

Key Features
Accurate Sentiment Analysis: Classify reviews into positive, negative, or neutral categories to understand customer sentiment.
Thematic Aggregation: Identify common themes and key points from multiple reviews to provide a consolidated overview.
Coherent Summaries: Generate concise summaries that capture the essence of individual feedback using both extractive and abstractive text summarization techniques.
User-Friendly Display: Present reviews in an easy-to-read format, including key insights, pros and cons, star ratings, sentiment graphs, and keyword clouds.
How It Works
Simple Setup: Enter your OpenAI API key in the sidebar for secure access to the GPT-4 Turbo model.
Input Reviews: Paste your reviews into the provided text area.
Analyze and Summarize: Click the ‘Convert’ button to perform analysis and generate summaries.
Setting Up the Environment
Imports:

Imports necessary libraries: streamlit, libraries from lyzr_automata

pip install lyzr_automata streamlit
Enter fullscreen mode Exit fullscreen mode
import streamlit as st
from lyzr_automata.ai_models.openai import OpenAIModel
from lyzr_automata import Agent,Task
from lyzr_automata.pipelines.linear_sync_pipeline import LinearSyncPipeline
from PIL import Image
Enter fullscreen mode Exit fullscreen mode

Sidebar Configuration
We create a sidebar for user inputs, including an API key input for accessing the OpenAI GPT-4 model. This ensures that the API key remains secure.

api = st.sidebar.text_input("Enter our OPENAI API KEY Here", type="password")
if api:
    openai_model = OpenAIModel(
        api_key=api,
        parameters={
            "model": "gpt-4-turbo-preview",
            "temperature": 0.2,
            "max_tokens": 1500,
        },
    )
else:
    st.sidebar.error("Please Enter Your OPENAI API KEY")
Enter fullscreen mode Exit fullscreen mode

api_documentation Function:

def review_analyst(reviews):
    review_agent = Agent(
        prompt_persona="You are an Expert Review Aggregator and Summarizer",
        role="Review Aggregator and Summarizer",
    )

    review_analysis_task = Task(
        name="Review Analysis Task",
        output_type=OutputType.TEXT,
        input_type=InputType.TEXT,
        model=openai_model,
        agent=review_agent,
        log_output=True,
        instructions=f"""Perform sentiment analysis to classify reviews into positive, negative, or neutral categories.
        Aggregate reviews based on common themes, sentiments, and key points.Summarize multiple reviews into a single coherent review that captures the essence of individual feedback.
        Use techniques like text summarization (extractive and abstractive) to create concise summaries.
        Display consolidated reviews in a user-friendly format, highlighting key insights, pros and cons, and overall sentiment. 
        Provide visual aids like star ratings, sentiment graphs, and keyword clouds to enhance readability.

        Reviews: {reviews}

        ##Output Requirements:
        ##Movie Name:
        ##Overview:
        ##Summarized Reviews:
        ##Key Insights:
            ###Pros:
            ###Cons:
        ##Overall Sentiment:
            ###Star Ratings: ⭐(use this emoji for rating️) 
            ###Sentiment Graph:
            ###Keyword Cloud:

        """,
    )

    output = LinearSyncPipeline(
        name="review Analysis",
        completion_message="Review Analysis Done!",
        tasks=[
            review_analysis_task
        ],
    ).run()
    return output[0]['task_output']
Enter fullscreen mode Exit fullscreen mode

def review_analyst(reviews):: Defines a function named review_analyst that takes user-provided reviews as input.
review_agent = Agent(...): Creates an Agent object defining the prompt persona and role for the AI model. Here, the persona is an "Expert Review Aggregator and Summarizer".
review_analysis_task = Task(...): Creates a Task object specifying the review analysis task. This includes details like:
Task name: “Review Analysis Task”
Output and Input types (text)
The AI model to be used (openai_model)
The defined review_agent
Instructions for the model:
Perform sentiment analysis (positive, negative, neutral)
Aggregate reviews based on themes, sentiments, and key points.
Summarize reviews into a single coherent summary capturing individual feedback.
Use summarization techniques (extractive and abstractive) for concise summaries.
Display consolidated reviews in a user-friendly format with key insights, pros, cons, and overall sentiment.
Include visual aids like star ratings, sentiment graphs, and keyword clouds.
The instructions also specify the desired output format with sections for movie name, overview, summarized reviews, key insights (pros and cons), overall sentiment (including star ratings, sentiment graph, and keyword cloud).
output = LinearSyncPipeline(...): Creates a LinearSyncPipeline object specifying:
Pipeline name: “review Analysis”
Completion message: “Review Analysis Done!”
List of tasks to be executed: only the review_analysis_task in this case.
output.run(): Executes the pipeline, triggering the review analysis task using the defined model and instructions.
return output[0]['task_output']: Retrieves the output of the first task (the review analysis task) from the output list and returns it. This likely contains the analyzed and summarized reviews.

User Code Input:

review = st.text_area("Enter Your Reviews", height=300)
Enter fullscreen mode Exit fullscreen mode

review = st.text_area creates a text area for users to enter their Reviews. It sets the height to 300 pixels.

Generate Button and Output Display:

if st.button("Convert"):
    solution = review_analyst(review)
    st.markdown(solution)
Enter fullscreen mode Exit fullscreen mode

Defines a button labeled “Convert”. Clicking the button calls the review_analyst function with the user-provided reviews and displays the returned analysis (potentially including summarized reviews, key insights, and visualizations) using markdown formatting.
Running the App
Finally, run the app using the following command in your terminal:s

streamlit run app.py
Enter fullscreen mode Exit fullscreen mode

try it now: https://lyzr-review-analyst.streamlit.app/

For more information explore the website: Lyzr

Top comments (0)