derek0890 commited on
Commit
750c487
·
verified ·
1 Parent(s): 2f6bf9a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Initialize the text generation pipeline with caching
5
+ # Using a smaller model for better performance on free tier
6
+ generator = pipeline('text-generation', model='gpt2')
7
+
8
+ def generate_marketing_text(prompt, content_type, max_length=150, temperature=0.7):
9
+ """
10
+ Generate marketing text based on the prompt and content type using GPT-2
11
+ """
12
+ # Set a reasonable max_length to avoid timeouts
13
+ if max_length > 250:
14
+ max_length = 250
15
+
16
+ # Enhance the prompt based on content type
17
+ enhanced_prompt = f"Write a {content_type} about {prompt}. "
18
+
19
+ # Generate text
20
+ result = generator(
21
+ enhanced_prompt,
22
+ max_length=max_length,
23
+ temperature=temperature,
24
+ do_sample=True,
25
+ pad_token_id=50256
26
+ )
27
+
28
+ # Return the generated text
29
+ return result[0]['generated_text']
30
+
31
+ # Create Gradio interface
32
+ demo = gr.Interface(
33
+ fn=generate_marketing_text,
34
+ inputs=[
35
+ gr.Textbox(lines=3, placeholder="Enter your topic here...", label="Topic"),
36
+ gr.Radio(
37
+ ["social media post", "email newsletter", "product description", "ad copy"],
38
+ label="Content Type",
39
+ value="social media post"
40
+ ),
41
+ gr.Slider(minimum=50, maximum=250, value=150, step=10, label="Maximum Length"),
42
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Creativity (Temperature)")
43
+ ],
44
+ outputs=gr.Textbox(lines=10, label="Generated Marketing Content"),
45
+ title="AdGenAI - Marketing Content Generator",
46
+ description="Enter a topic and select content type to generate marketing content using AI."
47
+ )
48
+
49
+ # Launch the app with caching enabled for better performance
50
+ demo.launch(cache_examples=True)