Image generated by Gemini

Unleashing the Potential of LLMs: How Enterprises are Leveraging AI for Enhanced Services

From Chatbots to Automation: Exploring the Versatile Use Cases of LLMs in Enterprises

--

Introduction:

In today’s rapidly evolving digital landscape, enterprises are constantly seeking innovative ways to streamline their operations, enhance customer experiences, and gain a competitive edge. With the advent of Large Language Models (LLMs) and their remarkable ability to understand and generate human-like text, businesses are now poised to unlock a new era of artificial intelligence (AI) powered services. LLMs, such as OpenAI’s GPT series, Google’s Gemini, and Anthropic’s Claude, have emerged as game-changers, offering unparalleled opportunities for enterprises to revolutionize their offerings and redefine customer engagement. By harnessing the power of these advanced language models, companies can develop intelligent chatbots, automate customer support, personalize marketing campaigns, and extract valuable insights from vast amounts of unstructured data.

Contents:

👉Blaze Banking Introduction.
👉Problem: Overloaded Customer Support
👉Solution: LLM-Powered Multimodal Customer Support using Claude API or Open API or Gemini API or any LLMs
👉Apps for all Enterprise Use cases
👉Problem: Inconsistent and Time-Consuming Email Communication
👉Solution: AI-Powered Email Writing App
👉Problem: Lack of Customer Insights
👉Solution: Sentiment Analysis App
👉Problem: Inefficient Document Management
👉Solution: Text Classification for Document Organization
👉Problem: Ineffective and Generic Marketing Campaigns
👉Solution: Personalized Marketing Campaign Generator
👉Problem: Limited Financial Literacy Among Customers
👉Solution: AI-Powered Financial Education Platform
👉Problem: Lack of Personalized Investment Advice
👉Solution: AI-Driven Personalized Investment Advisor
👉Problem: Promoting Employee Wellness and Productivity
👉Solution: AI-Powered Personal Trainer for Employee Wellness
👉Productionizing the Apps
👉RAG With Video and Audio Files
👉Important Repos
👉Important AI Courses
👉References
👉Conclusion

Let’s explore Blaze Banking's use of AI and LLMs to revolutionize its online banking services. For our article, Blaze Banking is a fictional bank, and we have fictional employees, too. Let's dive in.

Image by the Author

Blaze Bank Introduction:

Blaze Banking is a cutting-edge online bank that caters to the digital-savvy Gen Z audience. With a focus on innovation and customer-centric services, Blaze Banking aims to redefine the banking experience for the next generation.

The bank offers a wide range of online banking services, including:
- Personal and business accounts
- Digital payments and money transfers
- Mobile banking app with intuitive user interface
- Investment and wealth management solutions
- 24/7 customer support through various channels

Image by the Author

Fictional Employees and Their Duties:

1. Zoe Thompson — Customer Support Manager
Zoe is responsible for overseeing the customer support team at Blaze Banking. Her main goals are to ensure high customer satisfaction, resolve customer inquiries and complaints efficiently, and continuously improve the support processes.

2. Liam Parker — Investment Advisor
Liam is a skilled investment advisor who helps Blaze Banking customers make informed investment decisions. He provides personalized investment recommendations based on customers’ financial goals, risk tolerance, and market conditions.

3. Avery Chen — Fraud Detection Specialist
Avery is part of the bank’s fraud detection unit. She monitors suspicious financial activities, investigates potential fraud cases, and implements measures to prevent fraudulent transactions and protect customers’ assets.

4. Ethan Gupta — Financial Reporting Analyst
Ethan is responsible for generating financial reports and analytics for Blaze Banking. He collects and analyzes financial data, prepares reports for stakeholders, and provides insights to support data-driven decision-making.

5. Mia Patel — AI and Innovation Lead
Mia is the head of Blaze Banking’s AI and innovation department. She explores emerging technologies, such as LLMs and AI, to identify opportunities for automation, enhancing customer experiences, and improving operational efficiency.

These fictional employees work together to ensure the smooth operation of Blaze Banking and deliver exceptional online banking services to their Gen Z customers.

Note:

The article “Unleashing the Potential of LLMs: How Enterprises are Leveraging AI for Enhanced Services” aims to explore the versatile use cases of Large Language Models (LLMs) in enterprises, ranging from chatbots to automation.

The code provided serves as a basic template demonstrating how LLMs, such as Claude API, can be utilized to address various enterprise problems. - While the code provides a starting point, it emphasizes that further development can be made to enhance the models and productionize them for real-world enterprise use cases.

Problem: Overloaded Customer Support:

Zoe Thompson, the Customer Support Manager at Blaze Banking, has been facing a significant challenge. With the rapid growth of the bank’s customer base, the volume of customer inquiries and support requests has surged. Zoe’s team is struggling to keep up with the increasing workload, leading to longer response times and customer dissatisfaction.

The customer support team receives inquiries through various channels, including phone calls, emails, live chat, and social media. Customers often have questions about account balances, transaction histories, payment issues, and more. The team also handles complaints and resolves technical problems related to the mobile banking app.

Zoe realizes that the current support processes are not scalable and require a significant amount of manual effort. She fears that if the situation persists, it could lead to a decline in customer satisfaction and loyalty, which could negatively impact the bank’s reputation and growth.

Solution: LLM-Powered Multimodal Customer Support:

Image by the Author

Mia Patel, the AI and Innovation Lead at Blaze Banking, proposes a solution to address the customer support challenges. She suggests leveraging an advanced language model to automate and enhance customer support through a multimodal approach.

The proposed solution involves developing an AI-powered customer support system that can handle inquiries across multiple channels, including text, voice, and images. The system would utilize an LLM like ChatGPT4 Claude 3 or Llama2 to understand and interpret customer inquiries, provide accurate and context-aware responses, and guide customers to relevant solutions.

Key features of the LLM-powered multimodal customer support system:
1. Natural Language Understanding: LLM can comprehend customer inquiries written in natural language, identifying the intent and extracting relevant information.

2. Multimodal Inputs: The system can handle text inputs, voice recordings, and images (e.g., screenshots) provided by customers, enabling a seamless support experience.

3. Personalized Responses: By integrating with the bank’s customer data, the system can provide personalized responses based on the customer’s profile, account information, and transaction history.

4. Contextual Guidance: An LLM can guide customers through step-by-step solutions, provide relevant information, and offer tips and recommendations based on the context of the inquiry.

5. Escalation to Human Agents: For complex or sensitive issues that require human intervention, the system can seamlessly escalate the inquiry to a human support agent, providing them with the necessary context and customer information.

KPIs and ROI:

The implementation of the LLM-powered multimodal customer support system is expected to bring significant benefits to Blaze Banking:

1. Reduced response times: The automated system can handle a large volume of inquiries simultaneously, reducing the average response time from hours to minutes.

2. Increased customer satisfaction: Customers receive accurate, personalized, and timely support, leading to higher satisfaction rates and positive feedback.

3. Cost savings: By automating routine inquiries and reducing the need for manual intervention, the bank can save on labor costs and allocate resources more efficiently.

4. 24/7 availability: The AI-powered system can provide support round the clock, ensuring customers can get assistance whenever they need it.

5. Scalability: The system can easily scale to handle the growing customer base and support volumes without compromising on quality.

By implementing the LLM-powered multimodal customer support system, Blaze Banking can expect a 30% reduction in average response times, a 25% increase in customer satisfaction scores, and a 20% reduction in support costs within the first year of deployment.

Mia presents the solution and its potential impact to Zoe and the management team, emphasizing how it aligns with Blaze Banking’s vision of delivering exceptional customer experiences. Excited about the possibilities, they decide to move forward with the implementation, marking a significant milestone in the bank’s digital transformation journey.

Image by the Author

The POC was like

Image by the Author
Image by the Author

Customers might call and ask for support:

Image by the Author
Image by the Author

Image Analysis :

Image by the Author
Image by the Author
Image by the Author

Again in this whole article, we will be using Streamlit. So just a quick refresher on Streamlit below:

Install Streamlit: pip install streamlit

Run a Streamlit App: Navigate to your app's directory in the command line and
execute streamlit run your_script.py.

Documentation Link: Access the comprehensive Streamlit documentation for in
-depth guidance and tutorials at Streamlit Documentation.

Create a Simple App:
Import Streamlit: import streamlit as st

Display text: st.write("Hello, Streamlit!")

Widgets: Add interactive elements easily. For example,
slider_val = st.slider('Slide me', min_value=0, max_value=100)
lets users input a number through a slider.

Display Data: Use st.dataframe(your_dataframe) to display tables interactively.

Plotting: Show charts using commands like st.line_chart(data), where data
is a DataFrame or Numpy array.

Caching: Use @st.cache decorator to cache the output of functions and
speed up app loading times.

Layouts & Containers: Organize your app using st.sidebar for sidebar elements,
st.container() for grouping widgets, and st.columns(number) to align elements
side by side.

Session State: Manage user session state using st.session_state for
tracking user interactions and data throughout the session.

The code for the customer multimodal is below:

from PIL import Image
import speech_recognition as sr
import os
from io import BytesIO
import base64


with tab12:
st.write("Using Claude API")
st.subheader("Multimodal Customer Support")

# Customer input options
input_type = st.radio("Select Input Type", ("Text", "Image", "Voice"), key="input_type")

if input_type == "Text":
text_input = st.text_area("Enter your inquiry:", key="text_input")

elif input_type == "Image":
image_input = st.file_uploader("Upload an image:", type=["jpg", "jpeg", "png"], key="image_input")
image_text_input = st.text_area("Please provide more details about your inquiry:", key="image_text_input")

elif input_type == "Voice":
voice_input = st.file_uploader("Upload a voice recording:", type=["wav", "mp3"], key="voice_input")

if st.button("Submit Inquiry"):
if input_type == "Text":
inquiry_text = text_input
elif input_type == "Image":
if image_input is not None:
image = Image.open(image_input)

# Resize the image to a smaller size
max_size = (800, 800)
image.thumbnail(max_size)

# Display the uploaded image
st.image(image, caption="Uploaded Image", use_column_width=True)

# Convert image to bytes with increased compression level
buffered = BytesIO()
image.save(buffered, format="PNG", optimize=True, quality=50)
image_bytes = buffered.getvalue()

# Encode image bytes to base64
image_data = base64.b64encode(image_bytes).decode("utf-8")
image_media_type = "image/png"

inquiry_text = f"Image Input: {image_input.name}\n\nAdditional Details: {image_text_input}"

prompt = f"""
Act as a customer support agent for Blaze Banking and respond to the following customer inquiry:

{inquiry_text}

The customer has also uploaded an image related to the inquiry. Here is the image data:
<image>
{image_data}
</image>

Provide a helpful and personalized response, taking into account the following:
1. Analyze the uploaded image and extract relevant information from it.
2. Consider the additional details provided by the customer to better understand the context of the inquiry.
3. If applicable, integrate with the customer's profile, account information, and transaction history to provide a personalized response.
4. Guide the customer through step-by-step solutions, provide relevant information, and offer tips and recommendations based on the context of the inquiry and the uploaded image.
5. If the inquiry requires human intervention, escalate it to a human support agent and provide the necessary context and customer information.

Present the response in a clear, concise, and friendly manner.
"""

with st.spinner("Generating response..."):
response = get_claude_response(prompt, image_data, image_media_type)
st.markdown(response)
else:
st.warning("Please upload an image.")
st.stop()
elif input_type == "Voice":
if voice_input is not None:
# Convert voice recording to text using speech recognition
recognizer = sr.Recognizer()
with sr.AudioFile(voice_input) as source:
audio = recognizer.record(source)
try:
inquiry_text = recognizer.recognize_google(audio)
except sr.UnknownValueError:
st.warning("Speech recognition could not understand the audio.")
st.stop()
except sr.RequestError:
st.warning("Could not request results from the speech recognition service.")
st.stop()
else:
st.warning("Please upload a voice recording.")
st.stop()

prompt = f"""
Act as a customer support agent for Blaze Banking and respond to the following customer inquiry:

{inquiry_text}

Provide a helpful and personalized response, taking into account the following:
1. Identify the intent and extract relevant information from the inquiry.
2. If applicable, integrate with the customer's profile, account information, and transaction history to provide a personalized response.
3. Guide the customer through step-by-step solutions, provide relevant information, and offer tips and recommendations based on the context of the inquiry.
4. If the inquiry requires human intervention, escalate it to a human support agent and provide the necessary context and customer information.

Present the response in a clear, concise, and friendly manner.
"""

with st.spinner("Generating response..."):
response = get_claude_response(prompt)
st.markdown(response)


The code demonstrates a multimodal customer support system that accepts customer inquiries in three different formats: text, image, and voice. It utilizes the Anthropic Claude language model to generate personalized responses based on the customer’s input.

The code begins by importing the necessary libraries, including PIL for image processing, speech_recognition for converting speech to text, and BytesIO and base64 for image compression and encoding.

Within the Streamlit app, the code creates a radio button for the user to select the input type (text, image, or voice) and provides corresponding input fields based on the selection.

When the user submits an inquiry, the code processes the input based on the selected type:
- For text input, the inquiry text is directly used.
- For image input, the uploaded image is opened, resized, and compressed. The image is then encoded to base64 format. The inquiry text includes the image filename and any additional details provided by the user.
- For voice input, the uploaded voice recording is converted to text using the speech_recognition library.

The code then constructs a prompt for the Claude language model based on the inquiry text and any additional information (such as the encoded image data). The prompt instructs Claude to act as a customer support agent for Blaze Banking and provides guidelines for generating a personalized response.

The code sends the prompt to the Claude language model using the `get_claude_response` function (not shown in the provided code snippet) and retrieves the generated response.

Finally, the code displays the generated response to the user using Streamlit’s `st.markdown` function.

Throughout the code, there are error handling mechanisms to check if the user has uploaded an image or voice recording and to handle any exceptions that may occur during speech recognition.

Claude API or Open API or Gemini API or any LLMs:

The provided code demonstrates a multimodal customer support system that seamlessly integrates with the Anthropic Claude language model using the API key. However, the beauty of this code lies in its versatility and adaptability. With minimal modifications, the same codebase can be easily configured to work with various other language models and APIs, such as OpenAI’s API, Google’s Gemini API, or even open-source models like LLAMA.

By simply replacing the API key and adjusting the specific API calls and parameters, this customer support system can leverage the power of different language models based on your preferences and requirements. Whether you prefer the advanced capabilities of Anthropic Claude, the extensive training data of OpenAI’s models, the cutting-edge research behind Google’s Gemini, or the open-source flexibility of LLAMA, this code provides a solid foundation for building a robust and efficient customer support solution.

In summary, while the provided code showcases the integration with Anthropic Claude, its true strength lies in its adaptability to work with a wide range of language models and APIs. Whether you prefer proprietary or open-source models, this code offers a flexible and powerful foundation for building a state-of-the-art multimodal customer support system that can evolve and grow with your business needs.

Apps for all Enterprise Use cases:

Image by the Author

This article will cover the following Apps. I can’t explain all the apps, but I have explained most of them, and you will get an idea of how an LLM can be used by Enterprises.

1. Image Playground: This tab demonstrates how Claude can analyze and explain an uploaded image based on a user-provided prompt or question.
2. Financial Advisor: This app provides personalized financial advice and recommendations using Claude, based on user inputs such as age, income, savings, debt, investment experience, risk tolerance, and financial goals.
3. Personal Trainer: This app creates a personalized fitness plan with Claude, considering factors like age, gender, height, weight, activity level, fitness goals, workout preferences, available equipment, dietary restrictions, and medical conditions.
4. Technical Documentation Wizard: This app generates technical documentation for a product using Claude, based on details like product name, description, target audience, key features, installation steps, usage examples, API reference, troubleshooting guide, and FAQ.
5. Social Media Content Creator: This app creates social media content tailored to a specific brand, target audience, content theme, tone of voice, platform, post type, hashtags, and call-to-action.
6. Simple Math Quiz: This app generates a simple math quiz for children using Claude, customized by age group, number of questions, difficulty level, and included math operations.
7. Product Description Generator: This app generates compelling product descriptions using Claude, based on the product name, category, target audience, key features, benefits, unique selling points, brand voice, and desired description length.
8. Sentiment Analysis: This app performs sentiment analysis on user-provided customer feedback using Claude and VADER (Valence Aware Dictionary and sEntiment Reasoner), providing insights and suggestions for improvement.
9. Multimodal Customer Support: This app demonstrates a multimodal customer support system that can handle user inquiries in text, image, and voice formats, generating personalized responses using Claude.
10. AI-Powered Email Writing App: This app generates personalized email responses to customer inquiries using Claude, based on the inquiry type, customer name, email, and inquiry details.
11. Text Classification: This app classifies documents into predefined categories using Claude, either by manually entering the text or by uploading files (PDF, DOCX, TXT).
12. Personalized Marketing Campaign: This app creates personalized marketing campaigns with Claude, tailored to specific customer segments, campaign objectives, and channels. It can also generate campaigns based on uploaded customer data.
13. AI-Powered Financial Education Platform: This app provides a personalized financial education experience using Claude, offering a tailored learning path, interactive learning, and answers to user questions based on their profile and financial literacy assessment.
14. AI-Powered Financial Anomaly Detection: This app detects potential fraudulent transactions in real-time using Claude, providing explanations and enabling users to block transactions or contact customers for verification.
15. Harmful Post Detection and Removal: This app identifies and moderates harmful content in online communities using Claude, classifying posts as harmful or non-harmful, and providing tools for moderation and classification updates.

Image by the Author

Problem: Inconsistent and Time-Consuming Email Communication

Zoe Thompson, the Customer Support Manager at Blaze Banking, has identified a significant challenge in managing email communications with customers. With a growing customer base and an increasing volume of email inquiries, Zoe’s team is struggling to maintain consistency, accuracy, and efficiency in their email responses.

Customer support representatives often spend a considerable amount of time drafting emails, leading to longer response times and potential delays in addressing customer concerns. Moreover, the lack of standardized templates and guidelines results in variations in tone, style, and information provided across different representatives, which can impact the overall customer experience.

Zoe recognizes the need for a solution that can streamline email writing processes, ensure consistency in messaging, and improve the efficiency of customer support communications.

Solution: AI-Powered Email Writing App:

Image by the Author

Mia Patel, the AI and Innovation Lead, proposes the development of an AI-powered Email Writing App using Claude 3. The app will assist customer support representatives in composing high-quality, consistent, and personalized email responses to customer inquiries.

Key features of the AI-powered Email Writing App:

1. Email Templates: The app provides a library of pre-defined email templates for common customer inquiries and scenarios, ensuring consistency and accuracy in responses.

2. Personalization: Claude 3 analyzes customer data and inquiry context to generate personalized email content, addressing the specific needs and preferences of each customer.

3. Tone and Style Optimization: The app utilizes Claude 3’s language understanding capabilities to maintain a professional and empathetic tone in email communications, aligning with Blaze Banking’s brand voice and customer service guidelines.

4. Intelligent Suggestions: As representatives compose emails, the app provides real-time suggestions and recommendations for relevant information, attachments, and next steps based on the inquiry type and customer profile.

5. Compliance and Security: The app ensures that all email communications adhere to legal, regulatory, and security requirements, automatically flagging and preventing the inclusion of sensitive or inappropriate content.

KPIs and ROI:
The implementation of the AI-powered Email Writing App is expected to bring significant benefits to Blaze Banking:

1. Improved Response Time: By streamlining the email writing process and providing intelligent suggestions, the app can significantly reduce the time required to compose high-quality responses, leading to faster resolution of customer inquiries.

2. Increased Customer Satisfaction: Consistent, accurate, and personalized email communications can enhance customer satisfaction and build stronger relationships with Blaze Banking’s customers.

3. Enhanced Productivity: The app’s templates and suggestions enable customer support representatives to handle a higher volume of email inquiries efficiently, improving overall productivity and reducing the need for additional staffing.

4. Brand Consistency: Standardized email templates and tone optimization ensure that all customer communications align with Blaze Banking’s brand voice and values, creating a cohesive and professional customer experience.

5. Compliance and Risk Mitigation: The app’s built-in compliance checks and security features help Blaze Banking mitigate risks associated with inappropriate or sensitive content in email communications.

By implementing the AI-powered Email Writing App, Blaze Banking can expect a 30% reduction in average email response time, a 25% increase in customer satisfaction scores, and a 20% improvement in customer support representative productivity within the first year of deployment.

Mia and Zoe present the solution to the management team, highlighting the potential to revolutionize email communications and deliver exceptional customer service at scale. Recognizing the value of consistent and efficient email management, the management team approves the project, empowering Blaze Banking to leverage AI for enhanced customer support communications.

Image by the Author
Image by the Author

The code is

with tab13:
st.write("Using Claude API")
st.subheader("AI-Powered Email Writing App")

# Customer inquiry input
inquiry_type = st.selectbox("Select Inquiry Type", ("Account Issues", "Billing Questions", "Fraud Concerns", "Loan Inquiries", "General Feedback"), key="inquiry_type")
customer_name = st.text_input("Customer Name", key="customer_name")
customer_email = st.text_input("Customer Email", key="customer_email")
inquiry_details = st.text_area("Inquiry Details", key="inquiry_details")

if st.button("Generate Email Response"):
prompt = f"""
Act as a customer support representative for Blaze Banking and compose a personalized email response to the following customer inquiry:

Inquiry Type: {inquiry_type}
Customer Name: {customer_name}
Customer Email: {customer_email}
Inquiry Details: {inquiry_details}

Guidelines for generating the email response:
1. Use the appropriate email template based on the inquiry type.
2. Personalize the email content based on the customer's name, email, and inquiry details.
3. Maintain a professional and empathetic tone aligned with Blaze Banking's brand voice and customer service guidelines.
4. Provide relevant information, attachments, or next steps based on the inquiry type and customer profile.
5. Ensure compliance with legal, regulatory, and security requirements.
6. Include a clear and concise subject line for the email.

Present the email response in a well-structured format, including the subject line, greeting, body, closing, and signature.
"""

with st.spinner("Generating email response..."):
response = get_claude_response(prompt)

# Extract the subject line from the response
subject_line = response.split("\n")[0].strip()

# Display the email response
st.subheader("Generated Email Response")
st.write(f"Subject: {subject_line}")
st.write(response)

Image by the Author

Problem: Lack of Customer Insights:

Zoe Thompson, the Customer Support Manager at Blaze Banking, has been analyzing customer feedback and interactions to identify areas for improvement and better understand customer needs. However, with the growing volume of customer data coming from various channels such as surveys, reviews, social media, and customer support interactions, Zoe finds it challenging to manually process and extract meaningful insights from the unstructured text data.

The current process involves Zoe and her team manually reading through customer feedback, categorizing sentiments, and identifying common themes and issues. This approach is time-consuming, prone to human bias, and fails to capture the full spectrum of customer sentiments and opinions. Zoe realizes that to make data-driven decisions and improve customer satisfaction, Blaze Banking needs a more efficient and accurate way to analyze customer feedback at scale.

Solution: Sentiment Analysis App:

Image by the Author

Mia Patel, the AI and Innovation Lead, proposes the development of a Sentiment Analysis App that leverages Claude 3 to automatically analyze customer feedback and extract valuable insights. The app will process large volumes of text data from various sources, identify sentiment patterns, and provide actionable insights to improve customer experience and drive business decisions.

Key features of the Sentiment Analysis App:

1. Data Integration: The app integrates with multiple data sources, such as survey responses, customer reviews, social media mentions, and customer support transcripts, to collect and consolidate customer feedback data.

2. Sentiment Classification: Claude 3 is trained on a labeled dataset of customer feedback to accurately classify the sentiment of each piece of text as positive, negative, or neutral. The app can handle various language patterns, idioms, and context-specific expressions.

3. Topic Modeling: The app employs unsupervised learning techniques to identify common topics and themes within the customer feedback data. This helps Zoe and her team understand the main areas of concern or satisfaction for customers.

4. Insight Generation: The app generates visual dashboards and reports that summarize the sentiment analysis results, highlighting key metrics such as sentiment distribution, trend analysis, and topic prevalence. It also provides specific examples of customer feedback for each sentiment category and topic.

5. Alert System: The app can be configured to send real-time alerts to relevant stakeholders when there is a sudden spike in negative sentiment or when critical issues are identified, enabling proactive problem-solving and customer outreach.

KPIs and ROI:

The implementation of the Sentiment Analysis App is expected to bring significant benefits to Blaze Banking:

  1. Improved Customer Understanding: By analyzing customer feedback at scale, Blaze Banking can gain a deeper understanding of customer preferences, pain points, and expectations, enabling targeted improvements in products and services.

2. Increased Customer Satisfaction: By proactively addressing customer concerns and incorporating customer feedback into decision-making, Blaze Banking can enhance customer satisfaction and loyalty.

3. Operational Efficiency: The automated sentiment analysis process saves time and resources compared to manual analysis, allowing Zoe and her team to focus on high-impact initiatives and customer engagement strategies.

4. Competitive Advantage: By leveraging AI-powered sentiment analysis, Blaze Banking can quickly adapt to changing customer needs and stay ahead of the competition in terms of customer experience and satisfaction.

5. Data-Driven Decision Making: The insights generated by the Sentiment Analysis App enable Blaze Banking to make informed decisions based on customer data, reducing reliance on gut instincts and assumptions.

By implementing the Sentiment Analysis App, Blaze Banking can expect a 25% increase in customer satisfaction scores, a 30% reduction in customer churn, and a 20% improvement in customer lifetime value within the first year of deployment.

Mia and Zoe present the solution to the management team, highlighting the potential to unlock valuable customer insights and drive continuous improvement in customer experience. Recognizing the strategic importance of customer-centricity, the management team approves the project, empowering Blaze Banking to harness the voice of the customer and stay at the forefront of customer-centric innovation.

Image by the Author
Image by the Author
Image by the Author
Image by the Author

The code for sentiment analysis is:

with tab11:
st.write("Using Claude API")
st.subheader("Sentiment Analysis of Customer Feedback")

feedback_text = st.text_area("Enter customer feedback:", key="feedback_text")

prompt = f"""
Perform sentiment analysis on the following customer feedback:

{feedback_text}

Provide a detailed breakdown of the sentiment, including:
1. Overall sentiment (Positive, Negative, or Neutral)
2. Specific aspects or features mentioned in the feedback
3. Intensity of the sentiment for each aspect or feature
4. Key phrases or sentences that contribute to the sentiment
5. Suggestions for addressing any negative sentiments or improving customer satisfaction

Present the analysis in a clear and organized manner, using appropriate headings and bullet points.
"""

if st.button("Analyze Sentiment"):
with st.spinner("Analyzing sentiment using Claude..."):
response = get_claude_response(prompt)
st.markdown(response)

# Perform sentiment analysis using VADER
analyzer = SentimentIntensityAnalyzer()
sentiment_scores = analyzer.polarity_scores(feedback_text)

st.subheader("VADER Sentiment Analysis Results")
st.write("Positive:", sentiment_scores["pos"])
st.write("Negative:", sentiment_scores["neg"])
st.write("Neutral:", sentiment_scores["neu"])
st.write("Compound:", sentiment_scores["compound"])

# Interpret the compound score
if sentiment_scores["compound"] >= 0.05:
sentiment_label = "Positive"
elif sentiment_scores["compound"] <= -0.05:
sentiment_label = "Negative"
else:
sentiment_label = "Neutral"

st.write("Sentiment Label:", sentiment_label)

Within this tab, there is a text area where the user can enter customer feedback. The entered feedback is then passed to the Claude API along with a prompt to perform sentiment analysis.

The prompt asks Claude to provide a detailed breakdown of the sentiment, including the overall sentiment, specific aspects or features mentioned, the intensity of the sentiment for each aspect, key phrases or sentences contributing to the sentiment, and suggestions for addressing negative sentiments or improving customer satisfaction.

When the “Analyze Sentiment” button is clicked, the code sends the prompt to the Claude API using the get_claude_response() function. The response from Claude is then displayed using st.markdown().

In addition to using Claude for sentiment analysis, I’ve also included sentiment analysis using the VADER (Valence Aware Dictionary and sEntiment Reasoner) library. VADER is a rule-based sentiment analysis tool that provides sentiment scores for text data.

After displaying Claude’s sentiment analysis, the code performs sentiment analysis using VADER by creating an instance of the SentimentIntensityAnalyzer and calling its polarity_scores() method with the customer feedback text. The resulting sentiment scores (positive, negative, neutral, and compound) are displayed using st.write().

Finally, the code interprets the compound score to determine the overall sentiment label (Positive, Negative, or Neutral) based on predefined thresholds and displays the sentiment label using st.write().

Image by the Author

Problem: Inefficient Document Management:

Ethan Gupta, the Financial Reporting Analyst at Blaze Banking, has been grappling with the challenges of managing and organizing the bank’s vast collection of digital documents. With the increasing volume of financial reports, legal contracts, customer correspondence, and internal memos, Ethan finds it difficult to efficiently categorize and retrieve relevant documents when needed.

The current document management system relies on manual tagging and categorization, which is time-consuming and prone to inconsistencies. Employees often struggle to locate specific documents, leading to delays in reporting, decision-making, and customer service. Moreover, the lack of a standardized classification system results in duplication of efforts and storage inefficiencies.

Ethan recognizes the need for an automated and intelligent document classification system that can streamline document organization, improve search capabilities, and ensure consistent categorization across the organization.

Solution: Text Classification for Document Organization:

Image By the Author

Mia Patel, the AI and Innovation Lead, proposes the implementation of a Text Classification solution using Claude 3 to automatically classify and organize Blaze Banking’s digital documents. The solution will leverage Claude 3’s natural language understanding capabilities to analyze document content and assign appropriate categories, making it easier for employees to find and access relevant information.

Key features of the Text Classification for Document Organization solution:
1. Automated Document Classification: Claude 3 is trained on a labeled dataset of Blaze Banking’s documents to learn the patterns and characteristics of different document categories. It can then automatically classify new documents into predefined categories based on their content.

2. Multi-Label Classification: The solution can handle documents that belong to multiple categories, accurately assigning relevant labels to ensure comprehensive classification.

3. Custom Category Definition: Blaze Banking can define its own set of document categories based on its specific needs, such as financial reports, legal contracts, marketing materials, and customer communications.

4. Integration with Document Management System: The Text Classification solution seamlessly integrates with Blaze Banking’s existing document management system, enabling automated categorization and improved search functionality.

5. Continuous Learning: As new types of documents emerge or classification requirements change, the solution can be easily retrained and updated to adapt to evolving needs.

KPIs and ROI:
The implementation of the Text Classification for Document Organization solution is expected to bring significant benefits to Blaze Banking:

1. Improved Document Accessibility: By automatically classifying documents into relevant categories, employees can quickly and easily locate the information they need, reducing search time and increasing productivity.

2. Enhanced Collaboration: Consistent document classification promotes better collaboration among teams, as employees can access and share documents using a common taxonomy and understanding.

3. Reduced Manual Effort: Automating the document classification process eliminates the need for manual tagging and categorization, saving time and reducing the risk of human error.

4. Scalability: The solution can handle the growing volume of documents as Blaze Banking expands, ensuring efficient organization and management of information at scale.

5. Compliance and Audit Readiness: Accurate document classification helps Blaze Banking maintain compliance with regulatory requirements and enables faster retrieval of relevant documents during audits or legal proceedings.

By implementing the Text Classification for Document Organization solution, Blaze Banking can expect a 50% reduction in document search time, a 30% increase in employee productivity, and a 20% reduction in storage costs within the first year of deployment.

Mia and Ethan present the solution to the management team, highlighting the benefits of automating document classification and its impact on operational efficiency and information governance. Recognizing the value of streamlined document management, the management team approves the project, enabling Blaze Banking to leverage AI for intelligent document organization and retrieval.

Image by the Author
Image the Author
with tab14:
st.write("Using Claude API")
st.subheader("Text Classification for Document Organization")

# Document input
document_text = st.text_area("Enter the document text:", key="document_text")
document_type = st.selectbox("Select the document type:", ("Financial Report", "Legal Contract", "Marketing Material", "Customer Communication", "Internal Memo"), key="document_type")

if st.button("Classify Document"):
prompt = f"""
Act as a document classification assistant for Blaze Banking. Your task is to classify the following document into one or more predefined categories based on its content.

Document Type: {document_type}

Document Text:
{document_text}

Predefined Categories:
- Financial Reports
- Legal Contracts
- Marketing Materials
- Customer Communications
- Internal Memos

Instructions:
1. Analyze the document text and identify the most relevant categories based on its content.
2. Assign one or more categories to the document, considering the possibility of multi-label classification.
3. Provide a brief explanation for each assigned category, highlighting the key aspects of the document that led to the classification.
4. If the document does not fit into any of the predefined categories, suggest a new category that best describes the document's content.

Present the classification results in a clear and structured format, including the assigned categories and their explanations.
"""

with st.spinner("Classifying document..."):
response = get_claude_response(prompt)

# Display the classification results
st.subheader("Document Classification Results")
st.write(response)

st.subheader("Upload Documents for Classification")
uploaded_files = st.file_uploader("Choose documents to upload (PDF, DOCX, TXT)", accept_multiple_files=True)

if uploaded_files:
for uploaded_file in uploaded_files:
file_extension = uploaded_file.name.split(".")[-1].lower()

if file_extension == "pdf":
# Process PDF file
pdf_reader = PyPDF2.PdfReader(uploaded_file)
document_text = ""
for page in pdf_reader.pages:
document_text += page.extract_text()
elif file_extension == "docx":
# Process DOCX file
document = Document(uploaded_file)
document_text = "\n".join([paragraph.text for paragraph in document.paragraphs])
elif file_extension == "txt":
# Process TXT file
document_text = uploaded_file.read().decode("utf-8")
else:
st.warning(f"Unsupported file format: {file_extension}")
continue

prompt = f"""
Act as a document classification assistant for Blaze Banking. Your task is to classify the following document into one or more predefined categories based on its content.

Document Text:
{document_text}

Predefined Categories:
- Financial Reports
- Legal Contracts
- Marketing Materials
- Customer Communications
- Internal Memos

Instructions:
1. Analyze the document text and identify the most relevant categories based on its content.
2. Assign one or more categories to the document, considering the possibility of multi-label classification.
3. Provide a brief explanation for each assigned category, highlighting the key aspects of the document that led to the classification.
4. If the document does not fit into any of the predefined categories, suggest a new category that best describes the document's content.

Present the classification results in a clear and structured format, including the assigned categories and their explanations.
"""

with st.spinner(f"Classifying document: {uploaded_file.name}"):
response = get_claude_response(prompt)

# Display the classification results
st.subheader(f"Classification Results for {uploaded_file.name}")
st.write(response)
  1. We create a new tab (tab14) for the Text Classification for Document Organization solution.
  2. We provide an input field for the user to enter the document text and a selectbox to choose the document type.
  3. When the user clicks the “Classify Document” button, we create a prompt for the Claude language model. The prompt includes the document text, document type, and instructions for classifying the document into predefined categories.
  4. We send the prompt to the Claude language model using the get_claude_response function (not shown in the provided code snippet) and retrieve the classification results.
  5. We display the classification results to the user, including the assigned categories and their explanations.
  6. Additionally, we provide a file uploader that allows users to upload multiple documents (PDF, DOCX, TXT) for classification.
  7. For each uploaded file, we process the document based on its file extension:
  8. For PDF files, we use the PyPDF2 library to extract the text from each page.
  9. For DOCX files, we use the python-docx library to extract the text from each paragraph.
  10. For TXT files, we read the file content directly.
  11. We create a prompt for each uploaded document, similar to the prompt for the manual document input.
  12. We send each document’s prompt to the Claude language model and retrieve the classification results.
  13. Finally, we display the classification results for each uploaded document.
    Note: Make sure to install the required libraries (PyPDF2 and python-docx) before running the code.
Image by the Author

Problem: Ineffective and Generic Marketing Campaigns

Liam Parker, the Investment Advisor at Blaze Banking, has been collaborating with the marketing team to promote the bank’s investment products and services. However, he has noticed that the current marketing campaigns are often generic, untargeted, and fail to resonate with specific customer segments, resulting in low engagement and conversion rates.

The marketing team relies on broad demographic segmentation and sends out mass email campaigns with generic messaging, which often ends up in customers’ spam folders or remains unopened. Liam realizes that to effectively attract and retain customers, Blaze Banking needs to adopt a more personalized and data-driven approach to marketing.

Liam envisions a solution that can leverage customer data, preferences, and behavior to create highly targeted and personalized marketing campaigns that deliver relevant and compelling content to each individual customer.

Solution: Personalized Marketing Campaign Generator:

Image by the Author

Mia Patel, the AI and Innovation Lead, proposes the development of a Personalized Marketing Campaign Generator powered by Claude 3. The generator will analyze customer data, preferences, and behavior to create highly targeted and personalized marketing campaigns that resonate with each individual customer.

Key features of the Personalized Marketing Campaign Generator:
1. Customer Segmentation: The generator leverages advanced data analytics and machine learning algorithms to segment customers based on their demographics, financial goals, investment preferences, and engagement history.

2. Personalized Content Creation: Claude 3 is trained on a vast corpus of marketing content and customer data to generate highly personalized and relevant marketing messages, offers, and product recommendations for each customer segment.

3. Multi-Channel Campaign Execution: The generator integrates with various marketing channels, such as email, SMS, social media, and web platforms, to deliver personalized campaigns across multiple touchpoints, ensuring maximum reach and engagement.

4. Dynamic Content Optimization: The generator continuously monitors customer interactions and engagement metrics to dynamically optimize campaign content, offers, and messaging in real-time, improving relevance and conversion rates.

5. Performance Analytics and Insights: The generator provides detailed analytics and insights on campaign performance, customer engagement, and ROI, enabling Liam and the marketing team to make data-driven decisions and refine their marketing strategies.

KPIs and ROI:

The implementation of the Personalized Marketing Campaign Generator is expected to bring significant benefits to Blaze Banking:

1. Increased Customer Engagement: By delivering highly personalized and relevant marketing content, the generator can significantly improve customer engagement rates, including open rates, click-through rates, and conversions.

2. Higher Marketing ROI: Targeted and personalized campaigns are more likely to convert, resulting in higher marketing ROI and reduced customer acquisition costs.

3. Improved Customer Loyalty: Personalized marketing experiences foster stronger customer relationships and loyalty, leading to increased customer retention and lifetime value.

4. Competitive Differentiation: By leveraging AI-powered personalization, Blaze Banking can differentiate itself from competitors and establish a reputation for customer-centric marketing.

5. Scalability and Efficiency: The generator automates the process of creating and executing personalized campaigns, enabling Liam and the marketing team to scale their efforts efficiently and focus on strategic initiatives.

By implementing the Personalized Marketing Campaign Generator, Blaze Banking can expect a 40% increase in customer engagement rates, a 30% improvement in marketing ROI, and a 20% boost in customer loyalty within the first year of deployment.

Mia and Liam present the solution to the management team, highlighting the potential to revolutionize marketing efforts and drive business growth through personalization. Recognizing the value of data-driven marketing, the management team approves the project, empowering Blaze Banking to leverage AI for highly targeted and effective marketing campaigns.

Image by the Author
Image by the Author
Image by the Author
Image by the Author

The code is

with tab15:
st.write("Using Claude API")
st.subheader("Personalized Marketing Campaign Generator")

# Customer segment selection
customer_segment = st.selectbox("Select Customer Segment", ("Young Professionals", "Families", "Retirees", "High Net Worth Individuals"), key="customer_segment")

# Marketing campaign details
campaign_name = st.text_input("Campaign Name", key="campaign_name")
campaign_objective = st.selectbox("Campaign Objective", ("Increase Brand Awareness", "Promote New Product", "Encourage Signup", "Cross-Sell Services"), key="campaign_objective")
campaign_channels = st.multiselect("Campaign Channels", ("Email", "SMS", "Social Media", "Web"), key="campaign_channels")

if st.button("Generate Personalized Campaign"):
prompt = f"""
Act as a marketing campaign generator for Blaze Banking. Your task is to create a personalized marketing campaign for the selected customer segment.

Customer Segment: {customer_segment}

Campaign Details:
- Campaign Name: {campaign_name}
- Campaign Objective: {campaign_objective}
- Campaign Channels: {", ".join(campaign_channels)}

Instructions:
1. Analyze the selected customer segment and identify their preferences, behaviors, and financial goals.
2. Generate personalized marketing content, including messages, offers, and product recommendations tailored to the customer segment.
3. Develop a multi-channel campaign strategy to deliver the personalized content across the selected channels.
4. Provide suggestions for dynamic content optimization based on customer interactions and engagement metrics.
5. Include performance metrics and analytics to track the success of the campaign.

Present the personalized marketing campaign in a clear and structured format, including the following sections:
- Campaign Overview
- Customer Segment Insights
- Personalized Content Examples
- Multi-Channel Execution Plan
- Dynamic Optimization Strategies
- Performance Metrics and Analytics
"""

with st.spinner("Generating personalized marketing campaign..."):
response = get_claude_response(prompt)

# Display the generated campaign
st.subheader("Generated Personalized Marketing Campaign")
st.write(response)

st.subheader("Customer Data Upload")
uploaded_file = st.file_uploader("Choose a CSV file containing customer data", type="csv")

if uploaded_file is not None:
# Read the CSV file into a pandas DataFrame
customer_data = pd.read_csv(uploaded_file)

# Display the customer data
st.subheader("Uploaded Customer Data")
st.write(customer_data)

# Generate personalized campaigns for each customer segment
unique_segments = customer_data["Segment"].unique()

for segment in unique_segments:
prompt = f"""
Act as a marketing campaign generator for Blaze Banking. Your task is to create a personalized marketing campaign for the '{segment}' customer segment.

Customer Data:
{customer_data[customer_data["Segment"] == segment].to_string(index=False)}

Instructions:
1. Analyze the customer data and identify common preferences, behaviors, and financial goals within the segment.
2. Generate personalized marketing content, including messages, offers, and product recommendations tailored to the segment.
3. Develop a multi-channel campaign strategy to deliver the personalized content effectively.
4. Provide suggestions for dynamic content optimization based on customer interactions and engagement metrics.
5. Include performance metrics and analytics to track the success of the campaign.

Present the personalized marketing campaign in a clear and structured format, including the following sections:
- Campaign Overview
- Segment Insights
- Personalized Content Examples
- Multi-Channel Execution Plan
- Dynamic Optimization Strategies
- Performance Metrics and Analytics
"""

with st.spinner(f"Generating personalized campaign for {segment} segment..."):
response = get_claude_response(prompt)

# Display the generated campaign
st.subheader(f"Generated Campaign for {segment} Segment")
st.write(response)

In this code:

  1. We create a new tab (tab15) for the Personalized Marketing Campaign Generator.
  2. We provide options for the user to select the customer segment, campaign name, campaign objective, and campaign channels.
  3. When the user clicks the “Generate Personalized Campaign” button, we create a prompt for the Claude language model. The prompt includes the selected customer segment and campaign details, along with instructions for generating a personalized marketing campaign.
  4. We send the prompt to the Claude language model using the get_claude_response function (not shown in the provided code snippet) and retrieve the generated campaign.
  5. We display the generated personalized marketing campaign to the user, including sections for campaign overview, customer segment insights, personalized content examples, multi-channel execution plan, dynamic optimization strategies, and performance metrics and analytics.
  6. Additionally, we provide a file uploader that allows users to upload a CSV file containing customer data.
  7. If a file is uploaded, we read the CSV file into a pandas DataFrame and display the uploaded customer data.
  8. We identify the unique customer segments from the uploaded data and generate personalized campaigns for each segment.
  9. For each segment, we create a prompt that includes the segment-specific customer data and instructions for generating a personalized campaign.
  10. We send each segment’s prompt to the Claude language model and retrieve the generated campaign.
  11. Finally, we display the generated campaign for each customer segment.
Image by the Author

Problem: Limited Financial Literacy Among Customers

Mia Patel, the AI and Innovation Lead at Blaze Banking, has identified a significant challenge faced by many of the bank’s customers, particularly the younger generation. Through customer surveys and feedback, Mia has discovered that a considerable number of customers lack basic financial literacy skills, which hinders their ability to make informed financial decisions and achieve their long-term financial goals.

Customers often struggle with concepts such as budgeting, saving, investing, and managing debt. This lack of financial knowledge can lead to poor financial habits, missed opportunities, and potential financial distress. Mia realizes that as a responsible financial institution, Blaze Banking has an opportunity to educate and empower its customers to take control of their financial well-being.

However, traditional financial education programs, such as workshops and seminars, have limited reach and effectiveness. Mia believes that leveraging AI and personalization technologies can help deliver financial education at scale, tailored to the unique needs and preferences of each customer.

Solution: AI-Powered Financial Education Platform

Image by the Author

Mia proposes the development of an AI-powered Financial Education Platform that utilizes Claude 3 to provide personalized financial education content and interactive learning experiences to Blaze Banking’s customers.

Key features of the AI-powered Financial Education Platform:
1. Personalized Learning Paths: The platform assesses each customer’s financial literacy level, learning style, and financial goals to create personalized learning paths that cover relevant topics and concepts.

2. Interactive Content: The platform offers a variety of engaging content formats, such as articles, videos, quizzes, and gamified modules, to make financial education accessible and enjoyable for customers.

3. Natural Language Interaction: Claude 3 powers a conversational interface that allows customers to ask questions, seek clarification, and receive guidance on financial topics using natural language.

4. Progress Tracking and Rewards: The platform tracks each customer’s progress, provides regular feedback and recommendations, and offers rewards and incentives for completing learning milestones.

5. Integration with Banking Services: The platform seamlessly integrates with Blaze Banking’s online banking portal and mobile app, allowing customers to access financial education resources conveniently and apply their learning to real-life financial decisions.

KPIs and ROI:
The implementation of the AI-powered Financial Education Platform is expected to bring significant benefits to Blaze Banking:

1. Increased Financial Literacy: By providing personalized and engaging financial education, the platform can significantly improve customers’ financial knowledge and skills.

2. Enhanced Customer Engagement: The interactive and personalized nature of the platform can lead to higher customer engagement, increasing the frequency and duration of customer interactions with the bank.

3. Improved Financial Well-being: Customers who complete the learning paths are more likely to make informed financial decisions, leading to better financial outcomes and reduced financial stress.

4. Increased Product Adoption: As customers become more financially savvy, they are more likely to adopt and utilize the bank’s products and services effectively, driving revenue growth.

5. Stronger Brand Loyalty: By demonstrating a commitment to customers’ financial well-being, Blaze Banking can foster stronger brand loyalty and positive word-of-mouth referrals.

By implementing the AI-powered Financial Education Platform, Blaze Banking can expect a 30% increase in customer financial literacy scores, a 20% improvement in customer engagement metrics, and a 15% boost in product adoption rates within the first year of launch.

Mia presents the solution to the management team, highlighting the social impact and long-term benefits of investing in customer financial education. Recognizing the potential to create value for both customers and the bank, the management team approves the project, solidifying Blaze Banking’s position as a leader in customer-centric financial services.

with tab16:
st.write("Using Claude API")
st.subheader("AI-Powered Financial Education Platform")

# User profile input
user_name = st.text_input("Name", key="user_name")
user_age = st.number_input("Age", min_value=18, max_value=100, step=1, key="user_age")
user_income = st.number_input("Annual Income", min_value=0, step=1000, key="user_income")
user_goals = st.multiselect("Financial Goals", ("Save for Retirement", "Buy a Home", "Pay Off Debt", "Build Emergency Fund"), key="user_goals")

# Financial literacy assessment
financial_literacy_questions = [
"What is the primary purpose of a budget?",
"What is the difference between a checking account and a savings account?",
"What is the relationship between risk and return in investing?",
"What is the purpose of an emergency fund?",
"What is the difference between a credit card and a debit card?"
]

financial_literacy_score = 0
for i, question in enumerate(financial_literacy_questions):
st.subheader(f"Question {i+1}")
st.write(question)
user_answer = st.text_input(f"Your Answer", key=f"question_{i+1}")
if st.button(f"Submit Answer {i+1}"):
prompt = f"""
Act as a financial literacy assessor. Evaluate the user's answer to the following question:

Question: {question}
User Answer: {user_answer}

Provide a score between 0 and 1 based on the accuracy and completeness of the user's answer.
"""
score = float(get_claude_response(prompt).strip())
financial_literacy_score += score
st.write(f"Score: {score}")

if st.button("Generate Personalized Learning Path"):
prompt = f"""
Act as a financial education advisor for Blaze Banking. Your task is to create a personalized learning path for the user based on their profile and financial literacy assessment.

User Profile:
- Name: {user_name}
- Age: {user_age}
- Annual Income: {user_income}
- Financial Goals: {", ".join(user_goals)}

Financial Literacy Score: {financial_literacy_score} out of {len(financial_literacy_questions)}

Instructions:
1. Analyze the user's profile, financial goals, and financial literacy score.
2. Recommend a personalized learning path covering relevant financial topics and concepts.
3. Suggest engaging content formats, such as articles, videos, quizzes, and interactive modules, for each topic.
4. Provide ideas for gamification elements and rewards to motivate the user's progress.
5. Offer tips for integrating the learning with Blaze Banking's services and real-life financial decisions.

Present the personalized learning path in a clear and structured format, including the following sections:
- Learning Objectives
- Recommended Topics and Sequence
- Content Format Suggestions
- Gamification and Reward Ideas
- Integration with Banking Services
"""

with st.spinner("Generating personalized learning path..."):
response = get_claude_response(prompt)

# Display the generated learning path
st.subheader("Personalized Learning Path")
st.write(response)

st.subheader("Interactive Learning")
selected_topic = st.selectbox("Select a Financial Topic", ("Budgeting", "Saving", "Investing", "Credit", "Taxes"))
user_question = st.text_input("Ask a Question", key="user_question")

if st.button("Get Answer"):
prompt = f"""
Act as a financial education chatbot for Blaze Banking. Your task is to provide a clear and informative answer to the user's question.

Selected Topic: {selected_topic}
User Question: {user_question}

Instructions:
1. Provide a detailed answer to the user's question, focusing on the selected financial topic.
2. Explain any relevant concepts, terms, or strategies related to the question.
3. Offer practical examples or scenarios to illustrate your explanations.
4. Suggest additional resources or next steps for further learning.

Present your answer in a conversational and easy-to-understand manner.
"""

with st.spinner("Generating answer..."):
response = get_claude_response(prompt)

# Display the generated answer
st.subheader("Answer")
st.write(response)

In this code:

  1. We create a new tab (tab16) for the AI-powered Financial Education Platform.
  2. We collect user profile information, including name, age, annual income, and financial goals.
  3. We present a series of financial literacy assessment questions to the user and allow them to submit their answers. For each answer, we use Claude 3 to evaluate the accuracy and completeness and assign a score. The total financial literacy score is calculated based on the user’s answers.
  4. When the user clicks the “Generate Personalized Learning Path” button, we create a prompt for Claude 3 that includes the user’s profile information, financial literacy score, and instructions for generating a personalized learning path.
  5. We send the prompt to Claude 3 using the get_claude_response function (not shown in the provided code snippet) and retrieve the generated learning path.
  6. We display the generated personalized learning path to the user, including sections for learning objectives, recommended topics and sequence, content format suggestions, gamification and reward ideas, and integration with banking services.
  7. Additionally, we provide an interactive learning section where the user can select a financial topic and ask a question related to that topic.
    When the user clicks the “Get Answer” button, we create a prompt for Claude 3 that includes the selected topic, user question, and instructions for generating a clear and informative answer.
    We send the prompt to Claude 3 and retrieve the generated answer.
    Finally, we display the generated answer to the user.
Image by the Author
Image by the Author
Image by the Author
Image by the Author

Problem: Lack of Personalized Investment Advice:

Liam Parker, the Investment Advisor at Blaze Banking, has been facing challenges in providing personalized investment advice to the bank’s growing customer base. With a diverse range of customers, each with unique financial goals, risk tolerance levels, and investment preferences, Liam finds it increasingly difficult to offer tailored recommendations that meet the specific needs of every individual.

The current process involves Liam manually gathering customer information through questionnaires and interviews, analyzing market trends and investment options, and then crafting personalized investment plans. This approach is time-consuming and limits the number of customers Liam can effectively serve. Additionally, as market conditions change rapidly, Liam struggles to keep up with the latest developments and adjust the investment strategies accordingly.

Liam realizes that to scale his services and provide high-quality investment advice to a larger number of customers, he needs a more efficient and data-driven approach. He envisions a system that can automatically analyze customer profiles, market data, and investment options to generate personalized investment recommendations in real-time.

Solution: AI-Driven Personalized Investment Advisor:

Image by the Author

Mia Patel, the AI and Innovation Lead, collaborates with Liam to develop an AI-driven Personalized Investment Advisor system. The system leverages Claude 3’s natural language processing capabilities and machine learning algorithms to provide customized investment recommendations based on individual customer profiles and real-time market data.

Key features of the AI-driven Personalized Investment Advisor system:
1. Customer Profiling: The system collects and analyzes customer data, including financial goals, risk tolerance, investment horizon, and past investment behavior, to create detailed customer profiles.

2. Market Data Integration: The system integrates with real-time market data feeds, including stock prices, economic indicators, and news sentiment, to stay updated with the latest market developments.

3. Investment Option Analysis: Claude 3 analyzes various investment options, such as stocks, bonds, mutual funds, and ETFs, considering factors like historical performance, risk-return characteristics, and alignment with customer preferences.

4. Personalized Recommendations: By combining customer profiles, market data, and investment option analysis, the system generates personalized investment recommendations for each customer. The recommendations include suggested asset allocations, specific investment products, and rebalancing strategies.

5. Continuous Monitoring and Adjustment: The system continuously monitors the performance of the recommended investment portfolios and adjusts the strategies based on changing market conditions and customer needs.

KPIs and ROI:
The implementation of the AI-driven Personalized Investment Advisor system is expected to bring significant benefits to Blaze Banking:

1. Increased Customer Satisfaction: By providing personalized and data-driven investment advice, the bank can enhance customer satisfaction and build stronger relationships with its clients.

2. Expanded Customer Reach: The automated system enables Liam to serve a larger number of customers efficiently, expanding the bank’s investment advisory services to a wider audience.

3. Improved Investment Performance: The system’s ability to analyze vast amounts of market data and generate optimized investment recommendations can lead to improved investment returns for customers.

4. Operational Efficiency: Automating the investment advisory process reduces manual effort, allowing Liam to focus on high-value tasks such as strategic planning and customer engagement.

5. Competitive Advantage: By offering cutting-edge, AI-driven investment advisory services, Blaze Banking can differentiate itself from competitors and attract new customers.

By implementing the AI-driven Personalized Investment Advisor system, Blaze Banking can expect a 40% increase in customer satisfaction, a 60% expansion in the number of customers served, and a 20% improvement in average investment returns within the first year of deployment.

Mia and Liam present the solution to the management team, emphasizing the potential to revolutionize the bank’s investment advisory services. Impressed by the benefits and the opportunity to provide superior value to customers, the management team approves the project, positioning Blaze Banking at the forefront of AI-driven wealth management.

Image by the Author
Image by the Author
Image by the Author

The code is :

with tab5:
st.write("Using Claude API")
st.subheader("Financial Advisor")

age = st.slider("What is your age?", min_value=18, max_value=100, key="age")
education = st.selectbox(
"What is your highest level of education?",
[
"High School",
"Associate's Degree",
"Bachelor's Degree",
"Master's Degree",
"Doctoral Degree",
"Professional Degree",
],
key="education",
)
annual_income = st.number_input(
"What is your annual income ($)?", min_value=0, key="annual_income"
)
savings = st.number_input(
"What is your current total savings ($)?", min_value=0, key="savings"
)
debt = st.number_input(
"What is your current total debt ($)?", min_value=0, key="debt"
)
investment_experience = st.selectbox(
"What is your investment experience?",
["None", "Beginner", "Intermediate", "Advanced"],
key="investment_experience",
)
risk_tolerance = st.selectbox(
"What is your risk tolerance?",
["Low", "Moderate", "High"],
key="risk_tolerance",
)
financial_goals = st.multiselect(
"What are your financial goals?",
[
"Retirement Planning",
"Buying a Home",
"Saving for Education",
"Building Emergency Fund",
"Investing for Growth",
"Debt Reduction",
],
key="financial_goals",
)
additional_info = st.text_area(
"Provide any additional information for your financial advisor:",
key="additional_info",
)

prompt = f"""
As a financial advisor, provide personalized financial advice and recommendations based on the following client information:

Age: {age}
Education: {education}
Annual Income: ${annual_income}
Total Savings: ${savings}
Total Debt: ${debt}
Investment Experience: {investment_experience}
Risk Tolerance: {risk_tolerance}
Financial Goals: {", ".join(financial_goals)}

Additional Information:
{additional_info}

Provide a comprehensive financial plan addressing the following aspects:
- Budgeting and cash flow management
- Debt reduction strategies
- Savings and emergency fund planning
- Investment recommendations based on risk tolerance and goals
- Retirement planning and projections
- Recommendations for achieving specific financial goals
- Tax optimization strategies
- Insurance and risk management advice

Offer clear explanations and actionable steps for each recommendation. Use a friendly and professional tone, and organize your response with appropriate headings and bullet points.
"""

generate_advice = st.button("Generate Financial Advice", key="generate_advice")
if generate_advice and prompt:
financial_tab1, financial_tab2 = st.tabs(["Advice", "Prompt"])
with st.spinner("Generating your financial advice using Claude..."):
with financial_tab1:
response = get_claude_response(prompt)
if response:
st.write("Your personalized financial advice:")
st.write(response)
with financial_tab2:
st.text(prompt)

  1. It starts with the `with` statement to create a new tab named “Financial Advisor” using `st.tabs()`.
  2. Inside the tab, it displays the heading “Using Claude API” and a subheading “Financial Advisor” using `st.write()` and `st.subheader()`.
  3. It creates various input widgets for collecting user information:
  4. st.slider()` for selecting the user’s age, with a minimum value of 18 and a maximum value of 100.
  5. `st.selectbox()` for selecting the user’s highest level of education from a predefined list of options.
  6. `st.number_input()` for entering the user’s annual income, current total savings, and current total debt.
  7. `st.selectbox()` for selecting the user’s investment experience from a predefined list of options.
  8. `st.selectbox()` for selecting the user’s risk tolerance from a predefined list of options.
  9. `st.multiselect()` for selecting the user’s financial goals from a predefined list of options.
  10. `st.text_area()` for providing any additional information for the financial advisor.
  11. It defines a prompt string using an f-string, which incorporates the user’s input values into a template string.
  12. The prompt string serves as a set of instructions for the Claude language model, asking it to provide personalized financial advice and recommendations based on the user’s information.
  13. It includes specific aspects to address in the financial plan, such as budgeting, debt reduction, savings, investment recommendations, retirement planning, tax optimization, and insurance advice.
  14. The prompt also specifies the desired tone and organization of the response.
    - It creates a button labeled “Generate Financial Advice” using `st.button()`.
    - When the button is clicked and the prompt is available, it does the following:
    — It creates two tabs named “Advice” and “Prompt” using `st.tabs()`.
    — Inside the “Advice” tab, it displays a spinner with the message “Generating your financial advice using Claude…” using `st.spinner()`.
    — It calls the `get_claude_response()` function (assumed to be defined elsewhere) to generate a response from the Claude language model based on the provided prompt.
    — If a response is generated, it displays the personalized financial advice using `st.write()`.
    — Inside the “Prompt” tab, it displays the prompt string using `st.text()`.
Image by the Author

Problem: Promoting Employee Wellness and Productivity:

Zoe Thompson, the HR Manager at Blaze Banking, has noticed a decline in employee wellness and productivity. Many employees have been leading sedentary lifestyles, spending long hours sitting at their desks, which has resulted in increased health issues, reduced energy levels, and lower job satisfaction. Zoe recognizes that promoting physical fitness and well-being among employees is crucial for their overall health, productivity, and engagement at work.

However, Zoe faces challenges in motivating employees to prioritize their fitness and make time for regular exercise. Employees often cite lack of time, motivation, and guidance as barriers to maintaining an active lifestyle. Additionally, the diverse fitness levels, preferences, and health conditions of employees make it difficult to provide a one-size-fits-all solution.

Zoe understands that investing in employee wellness not only benefits the individuals but also contributes to a positive work culture and increased productivity for Blaze Banking. She desires a solution that can provide personalized fitness guidance, motivation, and support to employees, taking into account their unique needs and circumstances.

Solution: AI-Powered Personal Trainer for Employee Wellness:

Image by the Author

Mia Patel, the AI and Innovation Lead at Blaze Banking, proposes the development of an AI-powered Personal Trainer app using Claude, an advanced language model. The app aims to provide personalized fitness plans and guidance to employees, taking into account their individual goals, preferences, and constraints.

Key features of the AI-powered Personal Trainer app:
1. Personalized Fitness Assessment: Employees input their personal information, including age, gender, height, weight, activity level, fitness goals, workout preferences, available equipment, dietary restrictions, and medical conditions.

2. Tailored Fitness Plans: Based on the employee’s input, the app generates a comprehensive and personalized fitness plan. The plan includes a customized workout routine, exercise selection, sets, reps, rest times, and progression plan, tailored to the employee’s goals, preferences, and available resources.

3. Workout Guidance and Demonstrations: The app provides clear instructions and visual demonstrations for each exercise, ensuring proper form and technique. It also offers modifications and alternatives based on the employee’s fitness level and any medical conditions or limitations.

4. Nutrition and Recovery Advice: The app offers nutritional guidelines and sample meal plans aligned with the employee’s goals and dietary preferences. It also provides recommendations for rest, recovery, and flexibility/mobility work to support overall well-being.

5. Progress Tracking and Motivation: Employees can log their workouts, track their progress, and receive regular feedback and encouragement from the AI-powered personal trainer. The app celebrates milestones, offers rewards, and adapts the fitness plan based on the employee’s progress and feedback.

6. Integration with Wearables and Health Apps: The Personal Trainer app can sync with popular fitness wearables and health apps, allowing employees to easily track their activity, sleep, and other relevant metrics.

Benefits and Impact:
By implementing the AI-powered Personal Trainer app, Blaze Banking can:
- Promote employee wellness and encourage regular physical activity, leading to improved health, energy levels, and job satisfaction.
- Provide personalized fitness guidance and support, addressing the unique needs and preferences of each employee.
- Increase employee engagement and motivation by offering tailored plans, progress tracking, and regular encouragement.
- Foster a culture of wellness and demonstrate the company’s commitment to employee well-being.
- Enhance productivity and reduce absenteeism by supporting employees’ physical and mental health.
- Attract and retain top talent by offering innovative wellness initiatives and benefits.

The AI-powered Personal Trainer app, powered by Claude, offers a scalable and cost-effective solution for promoting employee wellness at Blaze Banking. By leveraging AI technology, the app can provide personalized fitness guidance and support to a large number of employees, without the need for individual human trainers.

Mia presents the solution to Zoe and the HR team, highlighting the benefits and potential impact on employee well-being and productivity. Impressed by the innovative approach and the opportunity to drive positive change, Blaze Banking decides to implement the AI-powered Personal Trainer app as part of their employee wellness program.

Image by the Author
Image by the Author
Image by the Author

The code is :

with tab6:
st.write("Using Claude API")
st.subheader("Personal Trainer")

name = st.text_input("What is your name?", key="name")
age = st.slider("What is your age?", min_value=18, max_value=100, key="pt_age")
gender = st.selectbox("What is your gender?", ["Male", "Female", "Other"], key="gender")
height = st.number_input("What is your height (in cm)?", min_value=0, key="height")
weight = st.number_input("What is your weight (in kg)?", min_value=0, key="weight")
activity_level = st.selectbox(
"What is your current activity level?",
["Sedentary", "Lightly Active", "Moderately Active", "Very Active"],
key="activity_level",
)
fitness_goal = st.selectbox(
"What is your primary fitness goal?",
["Lose Weight", "Build Muscle", "Improve Endurance", "Increase Flexibility"],
key="fitness_goal",
)
workout_preference = st.multiselect(
"What type of workouts do you prefer?",
["Weightlifting", "Cardio", "Yoga", "Pilates", "HIIT", "Calisthenics"],
key="workout_preference",
)
equipment_available = st.multiselect(
"What equipment do you have access to?",
["Dumbbells", "Barbells", "Resistance Bands", "Yoga Mat", "Cardio Machine"],
key="equipment_available",
)
dietary_restrictions = st.text_area("Do you have any dietary restrictions or preferences?", key="dietary_restrictions")
medical_conditions = st.text_area("Do you have any medical conditions or injuries?", key="medical_conditions")

prompt = f"""
As a personal trainer, create a personalized fitness plan based on the following client information:

Name: {name}
Age: {age}
Gender: {gender}
Height: {height} cm
Weight: {weight} kg
Activity Level: {activity_level}
Primary Fitness Goal: {fitness_goal}
Preferred Workouts: {", ".join(workout_preference)}
Equipment Available: {", ".join(equipment_available)}
Dietary Restrictions or Preferences: {dietary_restrictions}
Medical Conditions or Injuries: {medical_conditions}

Provide a comprehensive fitness plan including:
- Personalized workout routine (split into days or sessions)
- Exercise selection based on goals, preferences, and equipment availability
- Sets, reps, and rest times for each exercise
- Progression plan to increase difficulty over time
- Cardiovascular exercise recommendations
- Flexibility and mobility work
- Nutritional guidelines and sample meal plan
- Recommendations for recovery and rest
- Any necessary modifications based on medical conditions or limitations

Offer clear explanations and instructions for each component of the plan. Use a motivating and encouraging tone, and organize your response with appropriate headings and bullet points.
"""

generate_plan = st.button("Generate Fitness Plan", key="generate_plan")
if generate_plan and prompt:
plan_tab1, plan_tab2 = st.tabs(["Fitness Plan", "Prompt"])
with st.spinner("Generating your personalized fitness plan using Claude..."):
with plan_tab1:
response = get_claude_response(prompt)
if response:
st.write("Your personalized fitness plan:")
st.write(response)
with plan_tab2:
st.text(prompt)

  • Purpose: Acts as a virtual personal trainer to create personalized fitness plans.
    - User Inputs:
    — Basic personal information (name, age, gender).
    — Physical metrics (height, weight).
    — Activity level and fitness goals.
    — Workout preferences and available equipment.
    — Dietary restrictions and medical conditions.
    - Functionality:
    — Collects user data through various input widgets (text, slider, select box, multiselect, text area).
    — Generates a custom fitness plan using the Claude API, based on the user’s inputs.
    - Output:
    — The personalized fitness plan includes:
    — Workout routines (with detailed exercises, sets, reps, and rest times).
    — Cardiovascular, flexibility, and mobility recommendations.
    — Nutritional guidelines and sample meal plans.
    — Advice on recovery and rest.
    — Adjustments for any medical conditions or limitations.
    — The plan is presented in an encouraging tone, with clear instructions and organized under appropriate headings.
    - User Interface:
    — Features a button to trigger the generation of the fitness plan.
    — Displays the result in tabs, offering users the option to view both the generated fitness plan and the input prompt used for the Claude API.

Technical Documentation Wizard:

Image by the Author

Social Content Generator App:

Image by the Author
Image by the Author

Some more examples you can try:

1. Meeting Minutes Generator:
— Automatically generate concise and structured meeting minutes based on the audio or text input of a meeting.
— Helps in capturing key discussions, action items, and decisions made during meetings.

2. Contract Analysis and Summarization:
— Analyze legal contracts and agreements using LLMs to identify key clauses, obligations, and risks.
— Generate summarized versions of lengthy contracts, making it easier for stakeholders to review and understand.

3. Employee Onboarding Assistant:
— Develop an interactive chatbot that assists new employees during the onboarding process.
— Provide answers to common questions, guide them through paperwork, and offer resources for a smooth transition.

4. Competitive Intelligence Analyzer:
— Utilize LLMs to analyze news articles, press releases, and industry reports related to competitors.
— Extract insights, identify trends, and provide summaries to help businesses stay informed about their competitive landscape.

5. Customer Feedback Classifier:
— Automatically categorize and analyze customer feedback from various channels, such as surveys, reviews, and social media.
— Identify common themes, sentiment, and areas for improvement to enhance customer satisfaction.

6. HR Policy and Procedure Generator:
— Generate clear and consistent HR policies and procedures based on company guidelines and best practices.
— Ensure compliance with legal requirements and maintain a standardized approach to HR processes.

7. Sales Email Composer:
— Assist sales teams in crafting compelling and personalized email templates for different stages of the sales funnel.
— Optimize email content based on customer profiles, past interactions, and sales objectives.

8. Code Documentation Assistant:
— Generate comprehensive and user-friendly documentation for software code repositories.
— Explain code functionality, provide examples, and create API references to facilitate developer onboarding and collaboration.

9. Social Media Content Scheduler:
— Plan and schedule social media content across multiple platforms using LLMs.
— Generate engaging posts, captions, and hashtags aligned with brand guidelines and marketing campaigns.

10. Expense Report Auditor:
— Analyze employee expense reports using LLMs to identify potential anomalies, policy violations, or fraudulent claims.
— Flag suspicious entries for further review and streamline the expense approval process.

Image by the Author

The complete code of all the apps from 1 to 15 are :

Image by the Author

Productionizing the Apps:

For example, if Blaze Banking considers productionizing the streamlit apps, then follow the below steps:


1. Containerization:
- Dockerize each Streamlit app by creating a Dockerfile that includes the
necessary dependencies and configurations.
- Build Docker images for each app, ensuring they are lightweight and
secure.
- Push the Docker images to a private container registry (e.g., AWS ECR,
Azure Container Registry, Google Container Registry).

2. Infrastructure Setup:
- Provision a Kubernetes cluster on the chosen cloud platform (e.g., AWS
EKS, Azure AKS, Google GKE).
- Configure the cluster with appropriate node pools, networking, and s
ecurity settings.
- Set up necessary storage and database services (e.g., AWS RDS, Azure SQL
Database, Google Cloud SQL) for data persistence.

3. CI/CD Pipeline:
- Implement a CI/CD pipeline using a tool like Jenkins, GitLab CI/CD, or
Azure DevOps.
- Configure the pipeline to automatically build, test, and deploy the
Streamlit apps whenever changes are pushed to the source code repository.
- Include stages for building Docker images, running unit tests, and
deploying to the Kubernetes cluster.

4. Kubernetes Deployment:
- Create Kubernetes deployment manifests (YAML files) for each Streamlit
app, specifying the Docker image, replicas, resource requirements, and environment variables.
- Define Kubernetes services to expose the apps internally within the
cluster.
- Configure Kubernetes ingress or load balancers to expose the apps
externally and handle routing.

5. Scalability and High Availability:
- Configure Kubernetes Horizontal Pod Autoscaler (HPA) to automatically
scale the app replicas based on resource utilization.
- Implement readiness and liveness probes to ensure the apps are healthy
and can handle traffic.
- Use Kubernetes rolling updates or blue-green deployments for
zero-downtime deployments.

6. Data Processing and Pipelines:
- Use Apache Airflow to create and schedule data processing pipelines
for tasks like data ingestion, transformation, and model training.
- Integrate Airflow with the chosen cloud platform's storage and compute
services (e.g., AWS S3, Azure Blob Storage, Google Cloud Storage).
- Define Airflow DAGs (Directed Acyclic Graphs) to orchestrate the data
pipeline tasks and handle dependencies.

7. Monitoring and Logging:
- Implement monitoring and logging solutions to track the health and
performance of the Streamlit apps and infrastructure.
- Use tools like Prometheus and Grafana for metrics collection and
visualization.
- Utilize the cloud platform's logging services (e.g., AWS CloudWatch,
Azure Monitor, Google Cloud Logging) for centralized log management.

8. Security and Access Control:
- Implement authentication and authorization mechanisms to secure access to
the Streamlit apps and underlying infrastructure.
- Use cloud platform's identity and access management (IAM) services to
define roles and permissions.
- Encrypt sensitive data at rest and in transit using encryption services
provided by the cloud platform.

9. Performance Optimization:
- Optimize the Streamlit apps for performance by minimizing the app's
loading time and reducing memory usage.
- Implement caching mechanisms to store and reuse frequently accessed data.
- Use efficient data serialization formats like Apache Parquet or Avro
for data storage and retrieval.

10. Continuous Improvement:
- Regularly monitor and analyze app usage, user feedback, and performance
metrics to identify areas for improvement.
- Continuously iterate and update the apps based on user requirements and
business needs.
- Perform load testing and stress testing to ensure the apps can handle expected traffic and scale accordingly.

Image by the Author
Image by the Author

The docker file for the streamlit app will be:

# Use an official Python runtime as the base image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file to the working directory
COPY requirements.txt .

# Install the Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the Streamlit app code to the working directory
COPY multinodal_v2.py .

# Expose the port on which Streamlit will run (default is 8501)
EXPOSE 8501

# Set the entrypoint command to run the Streamlit app
CMD ["streamlit", "run", "multinodal_v2.py"]

RAG With Video and Audio Files:

This is the continuation of my previous article on RAG, which is

In the above article, I haven’t touched on how to convert the videos and audio files.

Everyone knows about GTC and Jensen. I want to do a RAG using this video file as the source.

Let’s dive in.

Part 1: Difficulties of using MP4 and Audio files in RAG applications

When working with RAG applications, incorporating MP4 and audio files can present several challenges:

1. File format compatibility: RAG models typically work with textual data, so MP4 and audio files need to be converted into a compatible format. This requires additional preprocessing steps to extract the relevant information from these files.

2. Transcription accuracy: Converting audio and video files to text relies on automatic speech recognition (ASR) systems. The accuracy of the transcription depends on factors like audio quality, background noise, accents, and domain-specific vocabulary. Inaccurate transcriptions can impact the performance of the RAG model.

3. Computational resources: Processing large volumes of MP4 and audio files can be computationally expensive. It requires significant storage space to store the files and sufficient processing power to convert them into text format.

4. Synchronization and alignment: When dealing with video files, synchronizing the transcribed text with the corresponding video frames can be challenging. Ensuring proper alignment is crucial for applications that rely on precise timing information.

5. Language and accent variations: RAG models may struggle with understanding and generating responses based on audio or video content that contains multiple languages, dialects, or heavy accents. This can impact the model’s ability to provide accurate and relevant information.

Let’s dive into the details of this process.

Part 2: Converting MP4 files to Audio

The first step in your process is to convert the MP4 files to audio format using the MoviePy library. Here’s how it works:

def convert_video_to_audio(video_path, audio_path):
video = VideoFileClip(video_path)
audio = video.audio
audio.write_audiofile(audio_path)

In this code snippet:
1. The `VideoFileClip` function from MoviePy is used to load the MP4 video file specified by `video_path`.
2. The audio component of the video is extracted using `video.audio`.
3. The `write_audiofile` method is called to save the audio as a separate file specified by `audio_path`.

This conversion step allows you to work with the audio content of the MP4 files independently, making it easier to process and transcribe.

video_path = "path/to/video.mp4"
audio_path = "path/to/audio.wav"
convert_video_to_audio(video_path, audio_path)

In this example, the `convert_video_to_audio` function is called with the paths to the input MP4 file and the desired output audio file. The function converts the video to audio and saves it as a WAV file.

Part 3: Converting Audio for Transcription:

After converting the MP4 files to audio, the next step is to prepare the audio for transcription. This involves converting the audio to a specific format that is compatible with the transcription models. Here’s how it’s done:

def convert_audio_for_transcription(original_audio_path, converted_audio_path):
audio = AudioSegment.from_file(original_audio_path)
audio = audio.set_frame_rate(16000).set_channels(1).set_sample_width(2)
audio.export(converted_audio_path, format="wav")

In this code snippet:
1. The `AudioSegment.from_file` function from the Pydub library is used to load the original audio file specified by `original_audio_path`.
2. The audio is then processed using the `set_frame_rate`, `set_channels`, and `set_sample_width` methods to set the desired audio properties. In this case, the audio is converted to a frame rate of 16000 Hz, mono channel, and a sample width of 2 bytes.
3. Finally, the processed audio is exported as a WAV file specified by `converted_audio_path` using the `export` method.

This conversion step ensures that the audio is in a suitable format for the transcription models to process accurately.

original_audio_path = "path/to/original_audio.wav"
converted_audio_path = "path/to/converted_audio.wav"
convert_audio_for_transcription(original_audio_path, converted_audio_path)

In this example, the `convert_audio_for_transcription` function is called with the paths to the original audio file and the desired converted audio file. The function processes the audio and saves it in the specified format.

Part 4: Transcribing with Vosk and Whisper Models:

With the audio files converted and prepared, the next step is to perform transcription using the Vosk and Whisper models. Let’s look at each transcription process separately.

Transcribing with Vosk:


def transcribe_with_vosk(audio_path):
wf = wave.open(audio_path, "rb")
recognizer = KaldiRecognizer(vosk_model, wf.getframerate())
text = []
while True:
data = wf.readframes(4000)
if len(data) == 0:
break
if recognizer.AcceptWaveform(data):
result = json.loads(recognizer.Result())
text.append(result.get('text', ''))
return ' '.join(text)

In this code snippet:
1. The `wave.open` function is used to open the audio file specified by `audio_path` in read-binary mode.
2. A `KaldiRecognizer` object is created using the pre-loaded Vosk model (`vosk_model`) and the frame rate of the audio file.
3. The audio file is processed in chunks of 4000 frames using a while loop.
4. For each chunk, the `AcceptWaveform` method of the recognizer is called to feed the audio data into the Vosk model.
5. If the model successfully processes the chunk, the recognized text is extracted from the `Result` method using `json.loads` and appended to the `text` list.
6. Finally, the recognized text chunks are joined together and returned as a single string.

Transcribing with Whisper:


def transcribe_with_whisper(audio_path):
result = whisper_model.transcribe(audio_path)
return result["text"]

In this code snippet:
1. The pre-loaded Whisper model (`whisper_model`) is used to transcribe the audio file specified by `audio_path`.
2. The `transcribe` method of the Whisper model is called with the audio file path, and the resulting transcription is stored in the `result` variable.
3. The transcribed text is extracted from the `result` dictionary using the “text” key and returned.


audio_path = "path/to/converted_audio.wav"
vosk_text = transcribe_with_vosk(audio_path)
whisper_text = transcribe_with_whisper(audio_path)

In this example, the `transcribe_with_vosk` and `transcribe_with_whisper` functions are called with the path to the converted audio file. Each function transcribes the audio using the respective model and returns the transcribed text.

Part 5: Saving Transcribed Text as PDF Files:

After obtaining the transcribed text from the Vosk and Whisper models, the next step is to save the text as PDF files. This allows for easy sharing and storage of the transcription results. Here’s how it’s done:


def save_text_to_pdf(text, pdf_path):
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
pdf.multi_cell(0, 10, text)
pdf.output(pdf_path)

In this code snippet:
1. An instance of the `FPDF` class from the fpdf library is created to generate a new PDF document.
2. A new page is added to the PDF document using the `add_page` method.
3. The font style and size are set using the `set_font` method. In this case, the Arial font with a size of 12 is used.
4. The `multi_cell` method is used to add the transcribed text to the PDF. The first argument `0` represents the width of the cell (set to 0 for automatic width), and the second argument `10` represents the height of each line.
5. Finally, the PDF document is saved to the specified file path using the `output` method.


vosk_text = "This is the transcribed text from the Vosk model."
whisper_text = "This is the transcribed text from the Whisper model."
pdf_path_vosk = "path/to/vosk_transcription.pdf"
pdf_path_whisper = "path/to/whisper_transcription.pdf"
save_text_to_pdf(vosk_text, pdf_path_vosk)
save_text_to_pdf(whisper_text, pdf_path_whisper)

In this example, the `save_text_to_pdf` function is called twice, once for the Vosk transcription and once for the Whisper transcription. The transcribed text and the desired PDF file paths are passed as arguments. The function creates PDF files with the transcribed text at the specified paths.

Part 6: Putting It All Together

Now let’s see how all the steps are combined in your code:


for video_path in video_files:
base_name = os.path.basename(video_path)
audio_path = os.path.join(audio_dir, f"{os.path.splitext(base_name)[0]}.wav")
converted_audio_path = os.path.join(audio_dir, f"{os.path.splitext(base_name)[0]}_converted.wav")
pdf_path_vosk = os.path.join(pdf_dir, f"{os.path.splitext(base_name)[0]}_vosk.pdf")
pdf_path_whisper = os.path.join(pdf_dir, f"{os.path.splitext(base_name)[0]}_whisper.pdf")

# Convert video to audio
convert_video_to_audio(video_path, audio_path)

# Convert audio for transcription
convert_audio_for_transcription(audio_path, converted_audio_path)

# Transcribe with Vosk
vosk_text = transcribe_with_vosk(converted_audio_path)
save_text_to_pdf(vosk_text, pdf_path_vosk)

# Transcribe with Whisper
whisper_text = transcribe_with_whisper(converted_audio_path)
save_text_to_pdf(whisper_text, pdf_path_whisper)
`

In this code snippet:
1. The code iterates over each video file path in the `video_files` list.
2. For each video file, the base name is extracted, and the paths for the audio files and PDF files are constructed using the `os.path.join` function.
3. The `convert_video_to_audio` function is called to convert the video to audio.
4. The `convert_audio_for_transcription` function is called to convert the audio to the desired format for transcription.
5. The `transcribe_with_vosk` function is called to transcribe the audio using the Vosk model, and the resulting text is saved as a PDF file using the `save_text_to_pdf` function.
6. Similarly, the `transcribe_with_whisper` function is called to transcribe the audio using the Whisper model, and the resulting text is saved as a separate PDF file.

This process is repeated for each video file, generating audio files and PDF files with the transcribed text for both the Vosk and Whisper models.

Once the PDF files are saved, you can convert them into embeddings, store them in the vector database, and continue the RAG application.Please refer to my article on how to create a RAG using PDF files.

The full code is:

The file folders and the video converted text.

Image by the Author

Important Repositories:

1.GCP-Gen AI

Sample code and notebooks for Generative AI on Google Cloud

2.Nvidia — Gen AI Examples:

3. LLM Course:

4. LLM Gen AI Repo:

5.GCP Repo:

AI Courses:

1.LLM Course:

2.Fast AI

3.Weights and Biases:

4.Deeplearning Ai:

5.GCP Gen AI Course:

6. Gen AI -AWS

7. Microsoft:

References:

Anthropic:

Anthropic Claude Documentation:
Official Website: https://www.anthropic.com/
Claude API Documentation: https://console.anthropic.com/docs/api
Anthropic GitHub Repository:
Official GitHub Repository: https://github.com/anthropics
Anthropic Blog:
Official Blog: https://www.anthropic.com/blog

Streamlit:

  1. Streamlit Documentation:

2. Streamlit GitHub Repository:

3. Streamlit Gallery:

4. Streamlit Blog:

5. Streamlit Community:

6. Streamlit Cheat Sheet:

Conclusion:

In conclusion, the rapid advancements in Large Language Models (LLMs) have opened up a world of possibilities for enterprises seeking to revolutionize their services and customer experiences. By harnessing the power of LLMs, businesses can develop intelligent chatbots, automate customer support, personalize marketing campaigns, and extract valuable insights from unstructured data. The provided code serves as a basic template, showcasing 15 diverse applications that demonstrate the versatility and potential of LLMs in addressing various enterprise challenges. However, it is important to recognize that this is just the beginning. Further development, fine-tuning, and productionization efforts are necessary to fully unlock the capabilities of LLMs and integrate them seamlessly into enterprise workflows.

--

--

ML/DS - Certified GCP Professional Machine Learning Engineer, Certified AWS Professional Machine learning Speciality,Certified GCP Professional Data Engineer .