Update app.py
Browse files
app.py
CHANGED
@@ -28,33 +28,6 @@ def model_inference(
|
|
28 |
if text == "" and images:
|
29 |
gr.Error("Please input a text query along the image(s).")
|
30 |
|
31 |
-
# Check if the input is related to marketing
|
32 |
-
marketing_keywords = [
|
33 |
-
"product", "brand", "advertisement", "marketing", "strategy", "comparison",
|
34 |
-
"analysis", "trend", "audience", "segmentation", "targeting", "demographics",
|
35 |
-
"psychographics", "behavioral", "content", "SEO", "SEM", "PPC", "email",
|
36 |
-
"marketing", "automation", "CRM", "lead", "nurturing", "conversion",
|
37 |
-
"optimization", "funnel", "landing", "page", "CTA", "banner", "ads",
|
38 |
-
"display", "retargeting", "remarketing", "social", "media", "platform",
|
39 |
-
"influencer", "marketing", "KOL", "brand", "ambassador", "hashtag",
|
40 |
-
"campaign", "ROI", "KPI", "metrics", "analytics", "Google", "Analytics",
|
41 |
-
"Facebook", "Ads", "Instagram", "Twitter", "LinkedIn", "YouTube", "TikTok",
|
42 |
-
"Snapchat", "Pinterest", "Quora", "Reddit", "Forums", "blog", "podcast",
|
43 |
-
"webinar", "event", "offline", "activation", "loyalty", "program", "referral",
|
44 |
-
"program", "affiliate", "marketing", "partnership", "collaboration", "influencer",
|
45 |
-
"relationship", "management", "brand", "voice", "tone", "messaging", "storytelling",
|
46 |
-
"visual", "design", "UX", "UI", "wireframe", "prototype", "user", "testing",
|
47 |
-
"A/B", "testing", "heatmaps", "surveys", "feedback", "customer", "journey",
|
48 |
-
"customer", "experience", "CX", "voice", "of", "customer", "VOC", "net",
|
49 |
-
"promoter", "score", "NPS", "CSAT", "customer", "support", "customer", "service",
|
50 |
-
"customer", "success", "customer", "acquisition", "customer", "retention",
|
51 |
-
"churn", "rate", "lifetime", "value", "CLV", "cohort", "analysis", "funnel",
|
52 |
-
"analysis", "conversion", "rate", "bounce", "rate", "engagement", "rate",
|
53 |
-
"time", "on", "site", "page", "views", "unique", "visitors", "session", "duration"
|
54 |
-
]
|
55 |
-
if not any(keyword in text.lower() for keyword in marketing_keywords):
|
56 |
-
return "Your question is not in the marketing area. Please upload another image or try again."
|
57 |
-
|
58 |
if isinstance(images, Image.Image):
|
59 |
images = [images]
|
60 |
|
@@ -98,9 +71,43 @@ def model_inference(
|
|
98 |
generated_texts = processor.batch_decode(generated_ids[:, generation_args["input_ids"].size(1):], skip_special_tokens=True)
|
99 |
return generated_texts[0]
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
gr.Markdown("**Disclaimer:** This app may not consistently follow prompts or handle complex tasks. However, adding a prefix to the assistant's response can significantly improve the output. You could also play with the parameters such as the temperature in non-greedy mode.")
|
105 |
with gr.Column():
|
106 |
image_input = gr.Image(label="Upload your Image", type="pil", scale=1)
|
@@ -185,10 +192,10 @@ with gr.Blocks(fill_height=True) as demo:
|
|
185 |
max_new_tokens, repetition_penalty, top_p], outputs=output)
|
186 |
|
187 |
footer = """
|
188 |
-
<div
|
189 |
-
<a href=
|
190 |
-
<a href=
|
191 |
-
<a href=
|
192 |
<br>
|
193 |
Made with π by Pejman Ebrahimi
|
194 |
</div>
|
|
|
28 |
if text == "" and images:
|
29 |
gr.Error("Please input a text query along the image(s).")
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
if isinstance(images, Image.Image):
|
32 |
images = [images]
|
33 |
|
|
|
71 |
generated_texts = processor.batch_decode(generated_ids[:, generation_args["input_ids"].size(1):], skip_special_tokens=True)
|
72 |
return generated_texts[0]
|
73 |
|
74 |
+
css = """
|
75 |
+
#app-container {
|
76 |
+
background-color: #f8f9fa;
|
77 |
+
padding: 20px;
|
78 |
+
border-radius: 10px;
|
79 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
80 |
+
}
|
81 |
+
|
82 |
+
#app-header {
|
83 |
+
text-align: center;
|
84 |
+
margin-bottom: 20px;
|
85 |
+
}
|
86 |
+
|
87 |
+
#app-description {
|
88 |
+
text-align: center;
|
89 |
+
margin-bottom: 20px;
|
90 |
+
}
|
91 |
+
|
92 |
+
#app-footer {
|
93 |
+
text-align: center;
|
94 |
+
margin-top: 20px;
|
95 |
+
font-size: 0.9em;
|
96 |
+
}
|
97 |
+
|
98 |
+
#app-footer a {
|
99 |
+
color: #007bff;
|
100 |
+
text-decoration: none;
|
101 |
+
}
|
102 |
+
|
103 |
+
#app-footer a:hover {
|
104 |
+
text-decoration: underline;
|
105 |
+
}
|
106 |
+
"""
|
107 |
+
|
108 |
+
with gr.Blocks(css=css, theme='JohnSmith9982/small_and_pretty') as demo:
|
109 |
+
gr.HTML("<h1 id='app-header'>Marketing Vision App π</h1>")
|
110 |
+
gr.HTML("<p id='app-description'>This app uses the <a href='https://huggingface.co/HuggingFaceM4/Idefics3-8B-Llama3' target='_blank'>HuggingFaceM4/Idefics3-8B-Llama3</a> model to answer questions related to various topics. Upload an image and a text query.</p>")
|
111 |
gr.Markdown("**Disclaimer:** This app may not consistently follow prompts or handle complex tasks. However, adding a prefix to the assistant's response can significantly improve the output. You could also play with the parameters such as the temperature in non-greedy mode.")
|
112 |
with gr.Column():
|
113 |
image_input = gr.Image(label="Upload your Image", type="pil", scale=1)
|
|
|
192 |
max_new_tokens, repetition_penalty, top_p], outputs=output)
|
193 |
|
194 |
footer = """
|
195 |
+
<div id='app-footer'>
|
196 |
+
<a href='https://www.linkedin.com/in/pejman-ebrahimi-4a60151a7/' target='_blank'>LinkedIn</a> |
|
197 |
+
<a href='https://github.com/arad1367' target='_blank'>GitHub</a> |
|
198 |
+
<a href='https://arad1367.pythonanywhere.com/' target='_blank'>Live demo of my PhD defense</a>
|
199 |
<br>
|
200 |
Made with π by Pejman Ebrahimi
|
201 |
</div>
|