Spaces:
Sleeping
Sleeping
File size: 2,344 Bytes
ff93ad0 0d8b8d6 ff93ad0 f722a57 eda6db8 ff93ad0 37255b7 ff93ad0 c8406ec 37255b7 abeac40 37255b7 f722a57 37255b7 f722a57 37255b7 ff93ad0 f722a57 ddb11ae f722a57 ff93ad0 eda6db8 ff93ad0 f722a57 ff93ad0 eda6db8 f722a57 ff93ad0 24747b5 ff93ad0 37255b7 24747b5 ff93ad0 eda6db8 ff93ad0 37255b7 1d8e0f9 ff93ad0 37255b7 ff93ad0 |
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import openai
import os
import gradio as gr
from dotenv import load_dotenv
import io
from PIL import Image
# Load environment variables (where your OpenAI key will be stored)
load_dotenv()
# Load the OpenAI API key from environment variables
openai.api_key = os.getenv("OPENAI_API_KEY").strip()
# Function to analyze the ad image (text analysis with GPT-4)
def analyze_ad(image):
# Convert the image to bytes (you can keep this for future multimodal capabilities)
image_bytes = io.BytesIO()
image.save(image_bytes, format='PNG')
image_bytes = image_bytes.getvalue()
# Placeholder: Using a simple prompt for text-based analysis (future multimodal support)
prompt = """
This is an advertisement. Please generate a marketing persona based on this ad and provide scores (out of 10) on the following:
1. Relevance to Target Audience
2. Emotional Engagement
3. Brand Consistency
4. Creativity
5. Persuasiveness
Explain your reasoning for each score and provide a final persona description.
"""
# Send the prompt to GPT-4-turbo for analysis
response = openai.chat.completions.create(
model="gpt-4-turbo",
messages=[
{"role": "system", "content": "You are a marketing expert analyzing an advertisement."},
{"role": "user", "content": prompt}
],
temperature=0.7,
max_tokens=400
)
# Extract the response text from the API output
result = response['choices'][0]['message']['content']
# Return the result for display
return result
# Function to process the image and run the analysis
def upload_and_analyze(image):
# Call the analyze_ad function to generate marketing insights
result = analyze_ad(image)
return result
# Gradio interface for Hugging Face deployment
iface = gr.Interface(
fn=upload_and_analyze,
inputs=gr.Image(type="pil", label="Upload Advertisement Image"), # Upload the ad image
outputs=gr.Textbox(label="Marketing Persona and Ad Analysis"),
title="Advertisement Persona and Scoring Analyzer",
description="Upload an advertisement image and get a marketing persona along with scores for Relevance, Emotional Engagement, Brand Consistency, Creativity, and Persuasiveness."
)
# Launch the app
if __name__ == "__main__":
iface.launch()
|