NikhilSetiya commited on
Commit
e321a99
·
2 Parent(s): b94ded8 7381380

Resolved merge conflict: fixed prompt file names

Browse files
Files changed (3) hide show
  1. agent.py +51 -0
  2. app.py +29 -0
  3. config/system_prompts/timing_prompt.txt +7 -0
agent.py CHANGED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import requests
3
+
4
+ GROQ_API_URL = "https://api.groqcloud.com/v1/chat/completions"
5
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY") # Secure key from Hugging Face Secrets
6
+
7
+ if not GROQ_API_KEY:
8
+ raise ValueError("GROQ_API_KEY is missing! Set it in Hugging Face Secrets.")
9
+
10
+ # Helper function to load system prompt from txt files
11
+ def load_prompt(filename):
12
+ with open(f'config/system_prompts/{filename}', 'r') as file:
13
+ return file.read()
14
+
15
+ # Function to call Groq API with system prompt and user input
16
+ def call_groq(system_prompt, user_input):
17
+ headers = {"Authorization": f"Bearer {GROQ_API_KEY}"}
18
+ payload = {
19
+ "model": "mixtral-8x7b-32768",
20
+ "messages": [
21
+ {"role": "system", "content": system_prompt},
22
+ {"role": "user", "content": user_input}
23
+ ]
24
+ }
25
+ print("Sending payload to Groq API...")
26
+ print(payload)
27
+ response = requests.post(GROQ_API_URL, json=payload, headers=headers)
28
+ print("Groq API response status:", response.status_code)
29
+ print("Groq API response body:", response.text)
30
+
31
+ if response.status_code != 200:
32
+ raise Exception(f"Groq API error: {response.status_code} - {response.text}")
33
+
34
+ data = response.json()
35
+ if 'choices' not in data or not data['choices']:
36
+ raise Exception("Groq API returned no choices.")
37
+
38
+ return data['choices'][0]['message']['content']
39
+
40
+ def ad_copy_agent(product, description, audience, tone):
41
+ system_prompt = load_prompt("ad_copy_prompt.txt")
42
+ user_input = f"Product: {product}\nDescription: {description}\nAudience: {audience}\nTone: {tone}"
43
+ return call_groq(system_prompt, user_input)
44
+
45
+ def sentiment_agent(social_data):
46
+ system_prompt = load_prompt("sentiment_prompt.txt")
47
+ return call_groq(system_prompt, social_data)
48
+
49
+ def timing_agent(platform):
50
+ system_prompt = load_prompt("timing_prompt.txt")
51
+ return call_groq(system_prompt, f"Platform: {platform}")
app.py CHANGED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from agent import ad_copy_agent, sentiment_agent, timing_agent
3
+
4
+ # Gradio UI definition
5
+ with gr.Blocks() as demo:
6
+ gr.Markdown("# 📈 Marketing AI Dashboard")
7
+
8
+ with gr.Tab("Ad Copy Generator"):
9
+ prod = gr.Textbox(label="Product")
10
+ desc = gr.Textbox(label="Description")
11
+ audience = gr.Textbox(label="Audience")
12
+ tone = gr.Textbox(label="Tone")
13
+ ad_output = gr.Textbox(label="Generated Ads")
14
+ ad_button = gr.Button("Generate Ads")
15
+ ad_button.click(ad_copy_agent, [prod, desc, audience, tone], ad_output)
16
+
17
+ with gr.Tab("Sentiment Analyzer"):
18
+ social_input = gr.Textbox(label="Social Media Mentions / Input")
19
+ sentiment_output = gr.Textbox(label="Sentiment Analysis")
20
+ sentiment_button = gr.Button("Analyze Sentiment")
21
+ sentiment_button.click(sentiment_agent, social_input, sentiment_output)
22
+
23
+ with gr.Tab("Post Timing Recommender"):
24
+ platform_input = gr.Textbox(label="Platform (e.g., Facebook, Instagram)")
25
+ timing_output = gr.Textbox(label="Recommended Times")
26
+ timing_button = gr.Button("Get Recommendations")
27
+ timing_button.click(timing_agent, platform_input, timing_output)
28
+
29
+ demo.launch()
config/system_prompts/timing_prompt.txt CHANGED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ You are a social media strategist. Recommend the 3 best time slots to post on social media for maximum engagement.
2
+
3
+ Rules:
4
+ - Base suggestions on typical platform engagement patterns.
5
+ - Mention time zones.
6
+ - Briefly explain why these times work.
7
+ - Suggest one experimental or underused time.