peterhartwigCF commited on
Commit
2225e44
·
verified ·
1 Parent(s): f6d760e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Initialize the o3 mini model (update the model identifier as needed)
5
+ o3_mini = pipeline("text2text-generation", model="o3mini-template-generator")
6
+
7
+ def generate_template(ref1, ref2, ref3, ref4, ref5):
8
+ # Collect non-empty references
9
+ references = [ref.strip() for ref in [ref1, ref2, ref3, ref4, ref5] if ref.strip()]
10
+ if not references:
11
+ return "Please provide at least one piece of reference copy."
12
+
13
+ # Combine all references into one prompt text
14
+ combined_references = "\n\n".join(references)
15
+
16
+ # Create a prompt that instructs the model to analyze the provided references
17
+ # and generate a structured template following the e-commerce copywriting guidelines.
18
+ prompt = (
19
+ "Analyze the following reference copy examples and generate a structured e-commerce "
20
+ "copywriting template that includes a header, template blocks, and control structures. "
21
+ "Follow this guide document:\n\n"
22
+ "E-commerce Copywriting Template Documentation (refer to internal guide for details)\n\n"
23
+ "Reference Copy:\n"
24
+ f"{combined_references}\n\n"
25
+ "Generate the final structured template output."
26
+ )
27
+
28
+ # Call the o3 mini model with the prompt
29
+ result = o3_mini(prompt, max_length=512, truncation=True)
30
+
31
+ # The model returns a list of dictionaries; extract the generated text.
32
+ template_output = result[0]['generated_text']
33
+ return template_output
34
+
35
+ iface = gr.Interface(
36
+ fn=generate_template,
37
+ inputs=[
38
+ gr.Textbox(label="Reference Copy 1", lines=3, placeholder="Paste your reference copy here"),
39
+ gr.Textbox(label="Reference Copy 2 (optional)", lines=3, placeholder="Paste your reference copy here"),
40
+ gr.Textbox(label="Reference Copy 3 (optional)", lines=3, placeholder="Paste your reference copy here"),
41
+ gr.Textbox(label="Reference Copy 4 (optional)", lines=3, placeholder="Paste your reference copy here"),
42
+ gr.Textbox(label="Reference Copy 5 (optional)", lines=3, placeholder="Paste your reference copy here")
43
+ ],
44
+ outputs=gr.Textbox(label="Structured Template"),
45
+ title="E-commerce Template Generator using O3 Mini",
46
+ description=(
47
+ "Provide up to five pieces of reference copy. This app calls the o3 mini model "
48
+ "to analyze your inputs and generate a structured template based on our e-commerce copywriting guidelines."
49
+ )
50
+ )
51
+
52
+ iface.launch()