File size: 1,677 Bytes
3f7b91f
 
 
 
1407c86
3f7b91f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM

# Load the fine-tuned model and tokenizer
model_name = "johnnymullaney/fine-tuned-distilgpt2-books"  # Path to the saved fine-tuned model

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

def generate_copy(book_title, book_author, book_genre, book_themes, book_description):
    prompt = f"""You are a marketing copywriter for an online bookstore.
Given the following book details, write three compelling landing page headlines and a short product description:

TITLE: {book_title}
AUTHOR: {book_author}
GENRE: {book_genre}
KEY THEMES: {book_themes}
DESCRIPTION: {book_description}

Landing Page Copy:
"""
    inputs = tokenizer.encode(prompt, return_tensors="pt")
    output = model.generate(
        inputs, 
        max_length=200, 
        temperature=0.7, 
        top_p=0.9, 
        do_sample=True
    )
    result = tokenizer.decode(output[0], skip_special_tokens=True)
    final_output = result.split("Landing Page Copy:")[-1].strip()
    return final_output

# Gradio UI
title_input = gr.Textbox(label="Book Title")
description_input = gr.Textbox(label="Book Description")
author_input = gr.Textbox(label="Author")
genre_input = gr.Textbox(label="Genre")
themes_input = gr.Textbox(label="Key Themes")

demo = gr.Interface(
    fn=generate_copy, 
    inputs=[title_input, author_input, genre_input, themes_input, description_input], 
    outputs="text",
    title="Dynamic Landing Page Copy Generator",
    description="Enter book details and get compelling marketing copy."
)

if __name__ == "__main__":
    demo.launch()