|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
generator = pipeline( |
|
|
"text-generation", |
|
|
model="EleutherAI/gpt-neo-1.3B" |
|
|
) |
|
|
|
|
|
|
|
|
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. |
|
|
""" |
|
|
|
|
|
enhanced_prompt = f"Write a {content_type} for the following product: {prompt}\nMake it persuasive, professional, and engaging." |
|
|
|
|
|
|
|
|
max_length = max_lengths.get(content_type, 400) |
|
|
|
|
|
|
|
|
result = generator( |
|
|
enhanced_prompt, |
|
|
max_length=max_length, |
|
|
temperature=temperature, |
|
|
do_sample=True, |
|
|
pad_token_id=50256 |
|
|
) |
|
|
|
|
|
return result[0]['generated_text'] |
|
|
|
|
|
|
|
|
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." |
|
|
) |
|
|
|
|
|
|
|
|
demo.launch() |
|
|
|