Update app.py
Browse files
app.py
CHANGED
@@ -17,8 +17,32 @@ llm = ChatGroq(
|
|
17 |
|
18 |
def niche_detection(text):
|
19 |
system_prompt = """
|
20 |
-
You are a social media niche expert.
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
User text : {text}
|
24 |
|
@@ -32,23 +56,29 @@ def niche_detection(text):
|
|
32 |
prompt = ChatPromptTemplate.from_messages([("system", system_prompt)])
|
33 |
chain = prompt | llm
|
34 |
output = chain.invoke({"text": text})
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
try:
|
37 |
-
return output.content.split('"niche": "')[1].split('"')[0]
|
38 |
-
except Exception:
|
39 |
-
return "Could not determine niche"
|
40 |
|
41 |
def content_styles(text):
|
42 |
system_prompt = """
|
43 |
-
You are an expert in analyzing social media content styles. Review the following Instagram
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
User text : {text}
|
54 |
|
@@ -60,11 +90,8 @@ def content_styles(text):
|
|
60 |
prompt = ChatPromptTemplate.from_messages([("system", system_prompt)])
|
61 |
chain = prompt | llm
|
62 |
output = chain.invoke({"text": text})
|
|
|
63 |
|
64 |
-
try:
|
65 |
-
return output.content.split('"content_styles": ')[1].split(']')[0].strip()
|
66 |
-
except Exception:
|
67 |
-
return "Could not determine content style"
|
68 |
|
69 |
# ---------------------------
|
70 |
# Gradio Interface
|
@@ -75,6 +102,7 @@ def analyze_post(text):
|
|
75 |
style = content_styles(text)
|
76 |
return niche, style
|
77 |
|
|
|
78 |
iface = gr.Interface(
|
79 |
fn=analyze_post,
|
80 |
inputs=gr.Textbox(lines=5, label="Instagram Post Text"),
|
@@ -82,7 +110,6 @@ iface = gr.Interface(
|
|
82 |
gr.Textbox(label="Detected Niche"),
|
83 |
gr.Textbox(label="Detected Content Style")
|
84 |
],
|
85 |
-
title="Instagram Post Analyzer",
|
86 |
description="Enter an Instagram post (caption + hashtags) to detect its niche and content style."
|
87 |
)
|
88 |
|
|
|
17 |
|
18 |
def niche_detection(text):
|
19 |
system_prompt = """
|
20 |
+
You are a highly skilled social media strategist and niche classification expert. Your task is to analyze the following Instagram caption and hashtags to identify the **main niche** the content belongs to.
|
21 |
+
|
22 |
+
Examples of possible niches include:
|
23 |
+
- Fitness
|
24 |
+
- Nutrition
|
25 |
+
- Mental Health
|
26 |
+
- Personal Finance
|
27 |
+
- Entrepreneurship
|
28 |
+
- Fashion
|
29 |
+
- Tech/Gadgets
|
30 |
+
- Parenting
|
31 |
+
- Travel
|
32 |
+
- Beauty/Skincare
|
33 |
+
- Relationships
|
34 |
+
- Digital Marketing
|
35 |
+
- Motivation
|
36 |
+
- Self-improvement
|
37 |
+
- Gaming
|
38 |
+
- Food/Cooking
|
39 |
+
- Home Decor
|
40 |
+
- Photography
|
41 |
+
- Music
|
42 |
+
- Art/Design
|
43 |
+
|
44 |
+
Analyze the content carefully and respond with ONLY the niche name (e.g., "Fitness" or "Travel").
|
45 |
+
** Don't retunr - " Could not determine niche "
|
46 |
|
47 |
User text : {text}
|
48 |
|
|
|
56 |
prompt = ChatPromptTemplate.from_messages([("system", system_prompt)])
|
57 |
chain = prompt | llm
|
58 |
output = chain.invoke({"text": text})
|
59 |
+
return output.content
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
|
|
|
|
|
|
|
|
|
64 |
|
65 |
def content_styles(text):
|
66 |
system_prompt = """
|
67 |
+
You are an expert in analyzing social media content styles. Review the following Instagram caption and hashtags and classify the dominant content style.
|
68 |
+
|
69 |
+
Choose from these content styles:
|
70 |
+
- Educational (teaching something new, how-to content)
|
71 |
+
- Motivational (encouraging action, inspiring change)
|
72 |
+
- Meme/Relatable (funny, relatable content)
|
73 |
+
- Personal Story (sharing personal experiences)
|
74 |
+
- Tips/Hacks (quick tips, life hacks)
|
75 |
+
- Promotional (selling products/services)
|
76 |
+
- Inspirational (uplifting quotes, positive messages)
|
77 |
+
- Opinion/Rant (personal opinions, controversial takes)
|
78 |
+
- Behind-the-Scenes (showing process, daily life)
|
79 |
+
- Question/Poll (asking for engagement)
|
80 |
+
|
81 |
+
Analyze the content and respond with ONLY the content style name (e.g., "Educational" or "Motivational").
|
82 |
|
83 |
User text : {text}
|
84 |
|
|
|
90 |
prompt = ChatPromptTemplate.from_messages([("system", system_prompt)])
|
91 |
chain = prompt | llm
|
92 |
output = chain.invoke({"text": text})
|
93 |
+
return output.content
|
94 |
|
|
|
|
|
|
|
|
|
95 |
|
96 |
# ---------------------------
|
97 |
# Gradio Interface
|
|
|
102 |
style = content_styles(text)
|
103 |
return niche, style
|
104 |
|
105 |
+
|
106 |
iface = gr.Interface(
|
107 |
fn=analyze_post,
|
108 |
inputs=gr.Textbox(lines=5, label="Instagram Post Text"),
|
|
|
110 |
gr.Textbox(label="Detected Niche"),
|
111 |
gr.Textbox(label="Detected Content Style")
|
112 |
],
|
|
|
113 |
description="Enter an Instagram post (caption + hashtags) to detect its niche and content style."
|
114 |
)
|
115 |
|