Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Load model and tokenizer
5tokenizer = AutoTokenizer.from_pretrained("Bhavin1905/Promogen-finetuned-model")
6model = AutoModelForCausalLM.from_pretrained("Bhavin1905/Promogen-finetuned-model")
7
8# Set device
9device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10model.to(device)
11
12# Generate advertisement
13def generate_ad(company_name, product_name, description):
14 prompt = f"Company: {company_name}\nProduct: {product_name}\nDescription: {description}\nAdvertisement:"
15
16 inputs = tokenizer.encode(prompt, return_tensors="pt").to(device)
17
18 with torch.no_grad():
19 outputs = model.generate(
20 inputs,
21 max_new_tokens=100,
22 temperature=0.8,
23 top_p=0.85,
24 do_sample=True,
25 pad_token_id=tokenizer.eos_token_id
26 )
27
28 generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
29 return generated_text.split("Advertisement:")[-1].strip()
30
31# Example usage
32ad_script = generate_ad(
33 company_name="TechCorp",
34 product_name="SmartWatch Pro",
35 description="Advanced fitness tracking with heart rate monitoring"
36)
37print(ad_script)1git clone https://github.com/cptghostriley/PromoGen.git
2cd PromoGen1from huggingface_hub import snapshot_download
2snapshot_download(
3 repo_id='Bhavin1905/Promogen-finetuned-model',
4 local_dir='./promogen_final_model'
5)1pip install -r requirements.txt
2python app.pyconfig.json: Model configurationgeneration_config.json: Generation parametersmodel-00001-of-00002.safetensors: Model weights (part 1)model-00002-of-00002.safetensors: Model weights (part 2)model.safetensors.index.json: Model indexspecial_tokens_map.json: Special tokens mappingtokenizer.json: Tokenizer configurationtokenizer.model: Tokenizer model filetokenizer_config.json: Tokenizer configuration1@misc{promogen2024,
2 title={PromoGen: AI-Powered Advertisement Generator},
3 author={Ashwin Mahawar, Bhavin, and Team PromoGen},
4 year={2024},
5 url={https://github.com/cptghostriley/PromoGen}
6}