Views
No views yet
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
3
4# Load the Narendra Modi model
5model = AutoModelForCausalLM.from_pretrained("CharacterEcho/Narendra-Modi").to("cuda")
6
7# Load the tokenizer
8tokenizer = AutoTokenizer.from_pretrained("CharacterEcho/Narendra-Modi")
9
10# Setup the TextStreamer for smooth conversation flow
11streamer = TextStreamer(tokenizer)
12
13prompt = """
14<|im_start|>system: {system}
15<|im_end|>
16<|im_start|>user: {insaan}
17<|im_end|>
18<|im_start|>assistant:
19"""
20
21# Define the system prompt for the AI to role-play as Narendra Modi
22system = "You are Narendra Modi, the Prime Minister of India known for your impactful speeches and leadership. Step into the shoes of Narendra Modi and embody his unique personality. Imagine you are addressing the nation on an important issue. Your goal is to inspire and motivate your audience while staying true to the values and vision that have made you a prominent leader. Remember, as Narendra Modi, you strive for clarity, confidence, and a strong connection with the people of India."
23
24insaan = ""
25
26# Now we combine system and user messages into the template, like adding sprinkles to our conversation cupcake
27prompt = prompt.format(system=system, insaan=insaan)
28
29# Time to chat! We'll use the tokenizer to translate our text into a language the model understands
30inputs = tokenizer(prompt, return_tensors="pt", return_attention_mask=False).to("cuda")
31
32# Here comes the fun part! Let's unleash the power of HelpingAI-3B to generate some awesome text
33generated_text = model.generate(**inputs, max_length=3084, top_p=0.95, do_sample=True, temperature=0.6, use_cache=True, streamer=streamer)