peterhartwigCF commited on
Commit
8ede8d4
·
verified ·
1 Parent(s): fb3ce3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -2,7 +2,7 @@ import os
2
  import gradio as gr
3
  import openai
4
 
5
- # Set your OpenAI API key (ensure this is set in your environment)
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
  def generate_template(ref1, ref2, ref3, ref4, ref5):
@@ -13,31 +13,35 @@ def generate_template(ref1, ref2, ref3, ref4, ref5):
13
 
14
  combined_references = "\n\n".join(references)
15
 
16
- # Build a detailed prompt that includes a summary of the guide document directions.
17
  prompt = f"""
18
  You are an expert in e-commerce copywriting. Your task is to analyze the following reference copy examples and generate a structured e-commerce copywriting template. Follow these guidelines extracted from our documentation:
19
 
20
- 1. The template must start with a header enclosed in square brackets. The header includes key-value pairs such as [type: UK website, style=true, language=English].
21
- 2. After the header, include template blocks enclosed in double curly braces {{ }}. These blocks define sections like an introduction, feature descriptions, technical specifications, and a conclusion.
22
- 3. Use control structures (enclosed in {{% %}}) for iterating over collections (for example, listing product features as a bulleted list).
23
- 4. Include clear instructions and modifiers within the template blocks (e.g., tone, style, length).
24
- 5. Ensure consistency, clarity, and adaptability for various products.
 
 
 
 
25
 
26
  Your generated template should include:
27
  - A header section.
28
  - An introduction block.
29
- - An example control structure for features.
30
  - A conclusion block.
31
 
32
- Reference Copy:
33
  {combined_references}
34
 
35
- Generate the final structured template that adheres to these directions.
36
- """
37
 
38
- # Call the OpenAI ChatCompletion API with the constructed prompt
39
  response = openai.ChatCompletion.create(
40
- model="gpt-3.5-turbo", # or your preferred model
41
  messages=[
42
  {"role": "system", "content": "You are a helpful assistant that generates structured e-commerce copywriting templates."},
43
  {"role": "user", "content": prompt}
@@ -60,7 +64,7 @@ iface = gr.Interface(
60
  ],
61
  outputs=gr.Textbox(label="Structured Template"),
62
  title="E-commerce Template Generator using OpenAI API",
63
- description="Provide up to five pieces of reference copy. This app calls the OpenAI API to analyze your inputs and generate a structured template based on the e-commerce copywriting guide."
64
  )
65
 
66
  iface.launch()
 
2
  import gradio as gr
3
  import openai
4
 
5
+ # Set your OpenAI API key (ensure this is set in your environment variables)
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
  def generate_template(ref1, ref2, ref3, ref4, ref5):
 
13
 
14
  combined_references = "\n\n".join(references)
15
 
16
+ # Build a prompt that includes the guide document directions and the reference copy
17
  prompt = f"""
18
  You are an expert in e-commerce copywriting. Your task is to analyze the following reference copy examples and generate a structured e-commerce copywriting template. Follow these guidelines extracted from our documentation:
19
 
20
+ 1. **Header Section:**
21
+ - Must be enclosed in square brackets (e.g., `[type: UK website, style=true, language=English]`).
22
+ 2. **Template Blocks:**
23
+ - Enclosed in double curly braces `{{ }}`.
24
+ - Include sections such as an introduction block, feature descriptions, technical specifications, and a conclusion block.
25
+ 3. **Control Structures:**
26
+ - Enclosed in `{% %}` tags to iterate over lists (for example, to generate a bulleted list of features).
27
+ 4. **Instructions and Modifiers:**
28
+ - Include clear guidance for tone, style, and length (e.g., `motivational, passionate, 1-2 sentences`).
29
 
30
  Your generated template should include:
31
  - A header section.
32
  - An introduction block.
33
+ - An example control structure for iterating over features.
34
  - A conclusion block.
35
 
36
+ **Reference Copy:**
37
  {combined_references}
38
 
39
+ Generate the final structured template that adheres to these guidelines.
40
+ """
41
 
42
+ # Call the OpenAI API using the new ChatCompletion interface
43
  response = openai.ChatCompletion.create(
44
+ model="gpt-3.5-turbo", # use your preferred model
45
  messages=[
46
  {"role": "system", "content": "You are a helpful assistant that generates structured e-commerce copywriting templates."},
47
  {"role": "user", "content": prompt}
 
64
  ],
65
  outputs=gr.Textbox(label="Structured Template"),
66
  title="E-commerce Template Generator using OpenAI API",
67
+ description="Provide up to five pieces of reference copy. The app calls the OpenAI API to analyze your inputs and generate a structured template based on the e-commerce copywriting guide."
68
  )
69
 
70
  iface.launch()