import torch
from transformers import T5ForConditionalGeneration, T5Tokenizer

# Check device (CPU or GPU)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# Load model and tokenizer
model = T5ForConditionalGeneration.from_pretrained("EnglishVoice/t5-base-keywords-to-headline")
tokenizer = T5Tokenizer.from_pretrained("EnglishVoice/t5-base-keywords-to-headline")
model = model.to(device)

# List of keywords for your sentences
keywords_list = [
    "access request, site number",
    "logs, mangate, two hours",
    "site number, access granted, construction"
]

# Generate headlines for each set of keywords
for keywords in keywords_list:
    print(f"Keywords: {keywords}")
    
    text = "headline: " + keywords
    encoding = tokenizer.encode_plus(text, return_tensors="pt")
    input_ids = encoding["input_ids"].to(device)
    attention_masks = encoding["attention_mask"].to(device)
    
    # Generate headlines using beam search
    beam_outputs = model.generate(
        input_ids=input_ids,
        attention_mask=attention_masks,
        do_sample=True,
        num_return_sequences=3,  # Generate 3 variations per input
        temperature=0.95,
        early_stopping=True,
        top_k=50,
        top_p=0.95,
    )
    
    # Print the generated headlines
    for i, beam_output in enumerate(beam_outputs):
        result = tokenizer.decode(beam_output, skip_special_tokens=True)
        print(f"Headline {i + 1}: {result}")
    print("-" * 50)



how can we make this better

Error displaying widget
Sentence: Thank you for calling me to see now for speaking. Can I assist you? I need access to a side, please. Glam key number? Charlie Papa 87. Charlie Papa 87. 87. Speaking to Leon. Leon, yeah. Side number? 353380. 353380. Side number three five double three eight oh three five double three eight oh, yeah, I'm going to the main listening. No, I'm saying how long? How long? Give us two hours, please. All right, you cannot make sure to close any of that. I'll do that. Thank you. All right, thank you. Bye. Bye-bye.

Keywords:
  - keywords, Thank you,  calling,  speaking,  side, 

Sentence: Thanks for calling me. It was nice. Yeah. that's nice yeah you need only mangate and the DC tank are all the logs including the DP and all the news sample What are you going to do inside? What are you going to do inside? What are you going to do inside? Oh, okay. There. Yes. Yes. Yes. Yes. Yes do you be inside? Maybe two hours. Yes, it is being granted with me. You recognize it? No, thank you. Thank you so much. I love you. Okay, you too. Thank you. Bye.

Keywords:
  - keywords: Thanks for calling me,  mangate,  DC tank

Sentence: Thank you for calling it to see you through to Vivian. May I ask you? Hi Vivian, how are you? I'm good, thanks. How are you? I'm okay. Can you please help me with access please, Nana? Certainly. Can I have a site number, Victor? Site number, Victor? Hello? Yes, it's Victor from World Construction. Can I have a site number? Site number? 352612. Is it a secondary? Yes, it's my number. You you from rural we are all construction every ID it's a to zero and zero so the teacher in class how my country outside to come give us five hours access granted is anything I can accept it I think I appreciate you thank you so much enjoy your day you too well bye

Keywords:
  - Vivian,  Nana,  World Construction,  site number,  secondary