|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
summarizer = pipeline("summarization", model="vapit/bart-large-cnn-finetuned-for-email-and-text") |
|
|
|
def summarize(text): |
|
if not text.strip(): |
|
return "Please enter your text to summarize." |
|
|
|
if len(text.split()) > 1024: |
|
return "Input too long. Please enter shorter sentences" |
|
|
|
|
|
result = summarizer(text, max_length=1024, min_length=30, do_sample=False) |
|
return result[0]['summary_text'] |
|
|
|
|
|
model = gr.Interface( |
|
fn=summarize, |
|
inputs=gr.Textbox(lines=6, placeholder="Enter your text here..."), |
|
outputs=gr.Textbox(label="Summary", lines=6), |
|
title="Beemmary 🐝", |
|
description="Summarize your day-to-day conversations, emails, or customer support chats! \n\nTip: Try to input detailed conversations or emails for more accurate summaries.", |
|
examples=[ |
|
[ |
|
"""Customer: Hi, I'm having trouble with my internet connection. It's been dropping all day. |
|
Agent: I'm sorry to hear that. Can you tell me if the issue is with Wi-Fi or a wired connection? |
|
Customer: It's the Wi-Fi. My laptop keeps disconnecting, and my phone isn't working either. |
|
Agent: Thank you. Have you tried restarting your router? |
|
Customer: Yes, twice. Still the same issue. |
|
Agent: Let me check if there are any outages in your area. Can I have your address, please? |
|
Customer: Sure, it's 123 Main Street. |
|
Agent: Thanks. There's actually a reported outage in your area, and technicians are working to resolve it. It should be fixed within 2 hours. |
|
Customer: Oh, okay. Thanks for letting me know. |
|
Agent: You're welcome! Sorry for the inconvenience. Is there anything else I can help you with today? |
|
Customer: No, that's all. Thanks!""" |
|
], |
|
[ |
|
"""Anna: Hey, are you free this weekend? I was thinking of going hiking. |
|
Tom: Oh, that sounds fun! I think I'm free on Saturday. |
|
Anna: Perfect! I found this new trail near the river. It's supposed to be beautiful. |
|
Tom: Nice! How long is the hike? |
|
Anna: About 3 hours. Not too hard, but we should bring some water and snacks. |
|
Tom: Absolutely. Should I bring my camera? I might want to take some pictures. |
|
Anna: Totally! I was planning to take some photos too. |
|
Tom: Awesome. Want me to drive? |
|
Anna: If you don’t mind, that would be great. |
|
Tom: No problem. What time should I pick you up? |
|
Anna: Maybe around 9 AM? |
|
Tom: Sounds good. Looking forward to it! |
|
Anna: Me too!""" |
|
], |
|
["""Subject: Project Update Needed |
|
|
|
Hi Sarah, |
|
|
|
I hope you're doing well. I wanted to check in on the status of the Q3 report. We need it finalized by next Monday for the management review. Do you think we can stay on track for that deadline? |
|
|
|
Best, |
|
Michael"""] |
|
] |
|
|
|
) |
|
|
|
if __name__ == "__main__": |
|
model.launch() |
|
|