Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import BartForConditionalGeneration, BartTokenizer
|
2 |
+
|
3 |
+
# Load the pre-trained BART model and tokenizer
|
4 |
+
model_name = "facebook/bart-large-cnn"
|
5 |
+
model = BartForConditionalGeneration.from_pretrained(model_name)
|
6 |
+
tokenizer = BartTokenizer.from_pretrained(model_name)
|
7 |
+
|
8 |
+
# Define a function to summarize a conversation
|
9 |
+
def summarize_conversation(conversation):
|
10 |
+
# Join the conversation into a single text (separate sentences by a space)
|
11 |
+
conversation_text = " ".join(conversation)
|
12 |
+
|
13 |
+
# Tokenize the conversation
|
14 |
+
inputs = tokenizer(conversation_text, return_tensors="pt", max_length=1024, truncation=True)
|
15 |
+
|
16 |
+
# Generate the summary
|
17 |
+
summary_ids = model.generate(inputs['input_ids'], num_beams=4, min_length=50, max_length=200, early_stopping=True)
|
18 |
+
|
19 |
+
# Decode the summary
|
20 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
21 |
+
return summary
|
22 |
+
|
23 |
+
# Sample conversation between agent and customer
|
24 |
+
conversation = [
|
25 |
+
"Hello, how can I assist you today?",
|
26 |
+
"I need help with my order. I haven't received it yet.",
|
27 |
+
"Can you provide me with your order number?",
|
28 |
+
"Sure, my order number is 123456.",
|
29 |
+
"Thank you. Let me check the status of your order.",
|
30 |
+
"It looks like your order was delayed due to some shipping issues.",
|
31 |
+
"When will I receive my order?",
|
32 |
+
"The order is expected to arrive within the next 2-3 days."
|
33 |
+
]
|
34 |
+
|
35 |
+
# Generate summary
|
36 |
+
summary = summarize_conversation(conversation)
|
37 |
+
|
38 |
+
# Print the summary
|
39 |
+
print("Conversation Summary:")
|
40 |
+
print(summary)
|