File size: 1,956 Bytes
750c487 d169e6c 864edbd d169e6c 864edbd d169e6c 864edbd 750c487 864edbd 750c487 d169e6c 750c487 d169e6c 864edbd d169e6c 864edbd d169e6c 750c487 864edbd 750c487 864edbd 750c487 d169e6c 750c487 864edbd 750c487 d169e6c 750c487 d169e6c 750c487 d169e6c 864edbd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import gradio as gr
from transformers import pipeline
# Load GPT-Neo model, optimized for CPU usage
generator = pipeline(
"text-generation",
model="EleutherAI/gpt-neo-1.3B" # Runs fine on CPU Basic tier
)
# Recommended length per content type
max_lengths = {
"social media post": 280,
"email newsletter": 800,
"product description": 600,
"ad copy": 400
}
def generate_marketing_text(prompt, content_type, _, temperature=0.7):
"""
Generate marketing text using GPT-Neo based on topic and content type.
"""
# Smart prompt engineering for better output
enhanced_prompt = f"Write a {content_type} for the following product: {prompt}\nMake it persuasive, professional, and engaging."
# Choose max_length based on content type
max_length = max_lengths.get(content_type, 400)
# Generate text using the model
result = generator(
enhanced_prompt,
max_length=max_length,
temperature=temperature,
do_sample=True,
pad_token_id=50256
)
return result[0]['generated_text']
# Gradio UI definition
demo = gr.Interface(
fn=generate_marketing_text,
inputs=[
gr.Textbox(lines=3, placeholder="Enter your product or topic here...", label="Topic"),
gr.Radio(
["social media post", "email newsletter", "product description", "ad copy"],
label="Content Type",
value="social media post"
),
gr.Slider(minimum=50, maximum=800, value=280, step=10, label="(Auto-set) Max Length", interactive=False),
gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Creativity (Temperature)")
],
outputs=gr.Textbox(lines=10, label="Generated Marketing Content"),
title="AdGenAI - Marketing Content Generator",
description="Free-tier friendly version using GPT-Neo 1.3B. Enter a topic and select the type of content you want to generate."
)
# Launch the app
demo.launch()
|