Tobidx commited on
Commit
a74cfea
·
verified ·
1 Parent(s): 99edec1

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +86 -13
  2. app .py +169 -0
  3. requirements.txt +6 -1
README.md CHANGED
@@ -1,13 +1,86 @@
1
- ---
2
- title: Sales Email Generator
3
- emoji: 💬
4
- colorFrom: yellow
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 5.0.1
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Smart Sales Email Generator
2
+
3
+ An AI-powered tool that generates contextual and professional follow-up emails based on previous customer interactions, using RAG, sentiment analysis and quality scoring.
4
+
5
+ ## AI Tools & Technologies
6
+ - RAG (Retrieval Augmented Generation) Implementation:
7
+ * Vector Store: ChromaDB for email template storage
8
+ * Embeddings: HuggingFace Sentence Transformers
9
+ * Similarity Search for context retrieval
10
+ - LangChain for orchestrating the RAG pipeline
11
+ - Hugging Face Transformers for sentiment analysis
12
+ - DeepSeek model for email generation
13
+ - Gradio for the interactive web interface
14
+ - Transformers pipeline for NLP tasks
15
+
16
+ ## Key Features
17
+ - RAG-powered contextual email generation
18
+ - Retrieval of similar past interactions
19
+ - Automated sentiment analysis for tone detection
20
+ - Customizable urgency levels and situation types
21
+ - Real-time email quality scoring
22
+ - Multiple pre-built templates for common scenarios
23
+ - Context-aware response generation
24
+
25
+ ## Technical Skills Demonstrated
26
+ - RAG System Implementation
27
+ - Vector Database Management
28
+ - Embedding Generation
29
+ - Natural Language Processing (NLP)
30
+ - Large Language Model (LLM) integration
31
+ - Prompt engineering
32
+ - API integration (Hugging Face Hub)
33
+ - Web application development
34
+ - Machine Learning model deployment
35
+ - GPU acceleration support
36
+ - Error handling and input validation
37
+
38
+ ## Architecture
39
+ - RAG Components:
40
+ * Vector Store for template storage
41
+ * Embedding model for text vectorization
42
+ * Similarity search for context retrieval
43
+ - Language Models:
44
+ * DeepSeek for generation
45
+ * BERT-based model for sentiment analysis
46
+ - Interface:
47
+ * Gradio for web UI
48
+ * Real-time processing
49
+
50
+ ## Use Cases
51
+ - Customer Service Follow-ups
52
+ - Complaint Resolution
53
+ - Service Issue Communication
54
+ - Payment Dispute Handling
55
+ - Product Query Responses
56
+ - General Business Communication
57
+
58
+ ## How to Use
59
+ 1. Enter the previous customer interaction
60
+ 2. Select the situation type from available options
61
+ 3. Choose tone (optional - will be automatically detected)
62
+ 4. Set urgency level (High/Medium/Low)
63
+ 5. Submit to generate a professional follow-up email with quality score
64
+
65
+
66
+ ## Development Stack
67
+ - Python 3.x
68
+ - LangChain Framework
69
+ - ChromaDB
70
+ - HuggingFace Transformers
71
+ - Gradio UI Framework
72
+ - CUDA support for GPU acceleration
73
+
74
+ ## Future Enhancements
75
+ - Enhanced RAG capabilities
76
+ - Expanded template database
77
+ - Response time optimization
78
+ - Direct email system integration
79
+ - Analytics and tracking capabilities
80
+ - Enhanced scoring system
81
+
82
+ ## License
83
+ MIT License
84
+
85
+ ## Author
86
+ [Tobi Ajibola]
app .py ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ import gradio as gr
4
+ from langchain import HuggingFaceHub
5
+ from langchain.chains import LLMChain
6
+ from langchain.prompts import PromptTemplate
7
+ from transformers import pipeline
8
+
9
+ #
10
+
11
+ # 2. Model Initialization
12
+ # Initialize sentiment analyzer
13
+ sentiment_analyzer = pipeline(
14
+ "sentiment-analysis",
15
+ model="finiteautomata/bertweet-base-sentiment-analysis",
16
+ device=0 if torch.cuda.is_available() else -1
17
+ )
18
+
19
+ # Initialize LLM
20
+ llm = HuggingFaceHub(
21
+ repo_id="deepseek-ai/deepseek-coder-33b-instruct",
22
+ model_kwargs={"temperature": 0.7}
23
+ )
24
+
25
+ # 3. Templates
26
+ email_template = PromptTemplate(
27
+ input_variables=["previous_interaction", "situation_type", "tone", "urgency"],
28
+ template="""Based on these details, generate a professional follow-up email:
29
+
30
+ Previous Interaction: {previous_interaction}
31
+ Situation Type: {situation_type}
32
+ Tone: {tone}
33
+ Urgency Level: {urgency}
34
+
35
+ Generate a personalized email that:
36
+ 1. Maintains {tone} tone
37
+ 2. Addresses the specific situation
38
+ 3. Provides clear next steps
39
+ 4. Is appropriate for {urgency} urgency level
40
+ """
41
+ )
42
+
43
+ scoring_template = """
44
+ Analyze this follow-up email carefully and provide scores on a scale of 1-10 for each category:
45
+
46
+ Email to analyze:
47
+ {email_text}
48
+
49
+ Please provide numerical scores and explanations in this exact format:
50
+
51
+ CLARITY SCORE: [1-10]
52
+ Explanation: [Why this score]
53
+
54
+ PROFESSIONALISM SCORE: [1-10]
55
+ Explanation: [Why this score]
56
+
57
+ ACTION ITEMS SCORE: [1-10]
58
+ Explanation: [Why this score]
59
+
60
+ PERSONALIZATION SCORE: [1-10]
61
+ Explanation: [Why this score]
62
+
63
+ OVERALL EFFECTIVENESS SCORE: [1-10]
64
+ Explanation: [Why this score]
65
+
66
+ IMPROVEMENT SUGGESTIONS:
67
+ 1. [First suggestion]
68
+ 2. [Second suggestion]
69
+ 3. [Third suggestion]
70
+ """
71
+
72
+ # 4. Create LangChain
73
+ email_chain = LLMChain(llm=llm, prompt=email_template)
74
+
75
+ # 5. Helper Functions
76
+ def analyze_sentiment(text):
77
+ try:
78
+ result = sentiment_analyzer(text)[0]
79
+ sentiment_to_tone = {
80
+ 'POS': 'Friendly',
81
+ 'NEU': 'Professional',
82
+ 'NEG': 'Apologetic'
83
+ }
84
+ return sentiment_to_tone.get(result['label'], 'Professional')
85
+ except Exception as e:
86
+ return 'Professional'
87
+
88
+ # 6. Main Generation Function
89
+ def generate_followup_email(previous_interaction, situation_type, tone, urgency):
90
+ try:
91
+ if not tone:
92
+ tone = analyze_sentiment(previous_interaction)
93
+
94
+ # Generate email
95
+ email_result = email_chain.run({
96
+ "previous_interaction": previous_interaction,
97
+ "situation_type": situation_type,
98
+ "tone": tone,
99
+ "urgency": urgency
100
+ })
101
+
102
+ # Generate score
103
+ score_result = llm(scoring_template.format(email_text=email_result))
104
+ return email_result, score_result
105
+ except Exception as e:
106
+ return f"Error generating email: {str(e)}", "Scoring unavailable"
107
+
108
+ # 7. Gradio Interface
109
+ demo = gr.Interface(
110
+ fn=generate_followup_email,
111
+ inputs=[
112
+ gr.Textbox(
113
+ label="Previous Interaction",
114
+ lines=5,
115
+ placeholder="Describe the previous interaction with the customer..."
116
+ ),
117
+ gr.Dropdown(
118
+ label="Situation Type",
119
+ choices=[
120
+ "Complaint Resolution",
121
+ "Service Issue",
122
+ "Payment Dispute",
123
+ "Product Query",
124
+ "General Follow-up"
125
+ ]
126
+ ),
127
+ gr.Dropdown(
128
+ label="Tone (Optional - will be automatically detected if not specified)",
129
+ choices=[
130
+ "",
131
+ "Professional",
132
+ "Apologetic",
133
+ "Friendly",
134
+ "Formal",
135
+ "Empathetic"
136
+ ]
137
+ ),
138
+ gr.Dropdown(
139
+ label="Urgency",
140
+ choices=["High", "Medium", "Low"]
141
+ )
142
+ ],
143
+ outputs=[
144
+ gr.Textbox(label="Generated Email"),
145
+ gr.Textbox(label="Email Score and Suggestions")
146
+ ],
147
+ title="Smart Sales Email Generator with Quality Scoring",
148
+ description="Generate and evaluate follow-up emails based on previous interactions",
149
+ examples=[
150
+ [
151
+ "Customer complained about slow website loading times and threatened to cancel subscription",
152
+ "Complaint Resolution",
153
+ "Apologetic",
154
+ "High"
155
+ ],
156
+ [
157
+ "Client requested information about premium features and pricing",
158
+ "Product Query",
159
+ "Professional",
160
+ "Medium"
161
+ ]
162
+ ]
163
+ )
164
+
165
+ # 8. Launch App
166
+ if __name__ == "__main__":
167
+ demo.launch()
168
+
169
+
requirements.txt CHANGED
@@ -1 +1,6 @@
1
- huggingface_hub==0.25.2
 
 
 
 
 
 
1
+ gradio
2
+ langchain
3
+ transformers
4
+ torch
5
+ emoji
6
+ huggingface_hub