Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,9 +18,14 @@ def analyze_ad(image):
|
|
18 |
image.save(image_bytes, format='PNG')
|
19 |
image_bytes = image_bytes.getvalue()
|
20 |
|
|
|
|
|
|
|
|
|
21 |
# Prompt for the marketing persona and scoring rubric
|
22 |
-
prompt = """
|
23 |
-
Analyze this advertisement
|
|
|
24 |
Then, provide a score (out of 10) for each of the following:
|
25 |
|
26 |
1. Relevance to Target Audience: Is the ad appealing to the intended demographic?
|
@@ -32,36 +37,19 @@ def analyze_ad(image):
|
|
32 |
Provide the persona description and the scores in table form with a final score.
|
33 |
"""
|
34 |
|
35 |
-
# Send the
|
36 |
-
response =
|
37 |
-
model="gpt-4-turbo
|
38 |
messages=[
|
39 |
{"role": "system", "content": "You are a marketing expert analyzing an advertisement."},
|
40 |
{"role": "user", "content": prompt}
|
41 |
],
|
42 |
-
functions=[
|
43 |
-
{
|
44 |
-
"name": "analyze_image",
|
45 |
-
"description": "Analyze an image and generate marketing insights",
|
46 |
-
"parameters": {
|
47 |
-
"type": "image",
|
48 |
-
"properties": {
|
49 |
-
"image": {
|
50 |
-
"type": "string",
|
51 |
-
"description": "The input advertisement image for analysis"
|
52 |
-
}
|
53 |
-
},
|
54 |
-
"required": ["image"]
|
55 |
-
}
|
56 |
-
}
|
57 |
-
],
|
58 |
-
function_call={"name": "analyze_image", "arguments": {"image": image_bytes}}, # Sending the image as input
|
59 |
temperature=0.7,
|
60 |
max_tokens=500
|
61 |
)
|
62 |
|
63 |
# Extract the response text from the API output
|
64 |
-
result = response
|
65 |
|
66 |
# Return the result for display
|
67 |
return result
|
|
|
18 |
image.save(image_bytes, format='PNG')
|
19 |
image_bytes = image_bytes.getvalue()
|
20 |
|
21 |
+
# Placeholder for ad text extracted from the image (since GPT-4-turbo doesn't support image-to-text natively)
|
22 |
+
# In a real scenario, you could integrate OCR to extract text or pass the image to a vision model.
|
23 |
+
ad_text = "This is a placeholder for text extracted from the image."
|
24 |
+
|
25 |
# Prompt for the marketing persona and scoring rubric
|
26 |
+
prompt = f"""
|
27 |
+
Analyze this advertisement and generate a marketing persona. The text in the ad says:
|
28 |
+
'{ad_text}'
|
29 |
Then, provide a score (out of 10) for each of the following:
|
30 |
|
31 |
1. Relevance to Target Audience: Is the ad appealing to the intended demographic?
|
|
|
37 |
Provide the persona description and the scores in table form with a final score.
|
38 |
"""
|
39 |
|
40 |
+
# Send the prompt to GPT-4-turbo for analysis
|
41 |
+
response = openai.ChatCompletion.create(
|
42 |
+
model="gpt-4-turbo", # Use GPT-4 turbo model
|
43 |
messages=[
|
44 |
{"role": "system", "content": "You are a marketing expert analyzing an advertisement."},
|
45 |
{"role": "user", "content": prompt}
|
46 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
temperature=0.7,
|
48 |
max_tokens=500
|
49 |
)
|
50 |
|
51 |
# Extract the response text from the API output
|
52 |
+
result = response['choices'][0]['message']['content'].strip()
|
53 |
|
54 |
# Return the result for display
|
55 |
return result
|