-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (39 loc) · 1.42 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pandas as pd
from transformers import pipeline
# Load pretrained model and tokenizer from Hugging Face
chatbot = pipeline('text-generation', model='gpt-3.5-turbo')
# Sample customer interaction data
data = {
'customer_id': [1, 2, 1, 3],
'interaction': [
'Looking for a new laptop',
'Need help with my phone bill',
'Interested in gaming laptops',
'Want to switch my internet plan'
]
}
# Create DataFrame
df = pd.DataFrame(data)
def get_customer_history(customer_id):
# Get past interactions of a customer
customer_history = df[df['customer_id'] == customer_id]['interaction'].tolist()
return customer_history
def generate_recommendation(history):
# Concatenate interaction history
history_text = " ".join(history)
# Generate recommendation
response = chatbot(f"Based on the history: {history_text} What would you recommend?")
return response[0]['generated_text']
def update_recommendations(customer_id):
# Get customer history
history = get_customer_history(customer_id)
if history:
# Generate and return recommendation
recommendation = generate_recommendation(history)
return recommendation
else:
return "No interaction history found for this customer."
# Example usage
customer_id = 1
recommendation = update_recommendations(customer_id)
print(f"Recommendation for customer {customer_id}: {recommendation}")