File size: 2,503 Bytes
c2f59fe
f1e2c23
684e707
c2f59fe
 
 
 
 
f1e2c23
684e707
 
 
c2f59fe
 
 
 
 
 
 
 
 
 
 
f1e2c23
 
c2f59fe
f1e2c23
c2f59fe
684e707
5ce8054
f1e2c23
 
 
c2f59fe
f1e2c23
 
 
684e707
f1e2c23
 
c2f59fe
 
 
 
 
 
f1e2c23
5ce8054
ea807ca
 
f1e2c23
684e707
 
 
 
5ce8054
f1e2c23
684e707
c2f59fe
5ce8054
684e707
5ce8054
c2f59fe
 
5ce8054
c2f59fe
 
 
5ce8054
c2f59fe
5ce8054
684e707
c2f59fe
 
 
 
 
 
 
f1e2c23
c2f59fe
ea807ca
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
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import gradio as gr
import groq
from dotenv import load_dotenv
from datetime import datetime

# Load environment variables
load_dotenv()

# Set API Key for Groq globally
groq.api_key = os.getenv("GROQ_API_KEY")

def load_system_prompt():
    try:
        current_dir = os.path.dirname(os.path.abspath(__file__))
        config_path = os.path.join(current_dir, "config", "system_prompt.txt")
        with open(config_path, 'r') as file:
            return file.read().strip()
    except Exception as e:
        print(f"Error loading system prompt: {str(e)}")
        return "You are a helpful social media research assistant."

SYSTEM_PROMPT = load_system_prompt()

def generate_ai_updates():
    """Generate AI updates using Groq API"""
    try:
        current_date = datetime.now().strftime("%B %d, %Y")
        
        response = groq.chat(
            messages=[
                {
                    "role": "system",
                    "content": SYSTEM_PROMPT
                },
                {
                    "role": "user",
                    "content": f"Please analyze and provide the latest AI developments and trends for {current_date}."
                }
            ],
            model="llama3-70b-8192",
            temperature=0.7,
            max_tokens=2048,
            top_p=0.9,
            frequency_penalty=0.1,
            presence_penalty=0.1
        )
        
        return response['choices'][0]['message']['content']
    
    except Exception as e:
        import traceback
        print("=== Full Groq API Error ===")
        print(traceback.format_exc())
        print("===========================")
        return "⚠️ Oops! Could not generate AI updates. Please try again later."

# Gradio app setup same as before
with gr.Blocks(title="AI Content Curator") as demo:
    gr.Markdown("# πŸ“ˆ AI Content Curator")
    gr.Markdown("Click to generate the latest AI developments and trends.")

    with gr.Row():
        with gr.Column():
            submit_btn = gr.Button("πŸš€ Generate Latest AI Updates")
        
        with gr.Column():
            output = gr.Textbox(
                label="πŸ”Ž AI Updates and Content Recommendations",
                lines=20,
                interactive=False,
                placeholder="Waiting for the latest AI trends..."
            )
    
    submit_btn.click(
        fn=generate_ai_updates,
        inputs=[],
        outputs=output
    )

if __name__ == "__main__":
    demo.launch(share=True)