setiyanikhil3 commited on
Commit
684e707
Β·
verified Β·
1 Parent(s): 92d83ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -1,34 +1,33 @@
1
  import os
2
  import gradio as gr
3
- import groq # No more Groq class
4
  from dotenv import load_dotenv
5
  from datetime import datetime
6
 
7
  # Load environment variables
8
  load_dotenv()
9
 
 
 
 
10
  def load_system_prompt():
11
- """Load and decode the system prompt from the config file"""
12
  try:
13
  current_dir = os.path.dirname(os.path.abspath(__file__))
14
  config_path = os.path.join(current_dir, "config", "system_prompt.txt")
15
-
16
  with open(config_path, 'r') as file:
17
  return file.read().strip()
18
  except Exception as e:
19
  print(f"Error loading system prompt: {str(e)}")
20
  return "You are a helpful social media research assistant."
21
 
22
- # Load the system prompt once
23
  SYSTEM_PROMPT = load_system_prompt()
24
 
25
  def generate_ai_updates():
26
  """Generate AI updates using Groq API"""
27
  try:
28
  current_date = datetime.now().strftime("%B %d, %Y")
29
- print(f"Loaded GROQ_API_KEY: {os.getenv('GROQ_API_KEY')}")
30
  response = groq.chat(
31
- api_key=os.getenv("GROQ_API_KEY"),
32
  messages=[
33
  {
34
  "role": "system",
@@ -36,7 +35,7 @@ def generate_ai_updates():
36
  },
37
  {
38
  "role": "user",
39
- "content": f"Please analyze and provide the latest AI developments and trends for {current_date}. Follow the verification workflow and create content as specified in the system prompt."
40
  }
41
  ],
42
  model="llama3-70b-8192",
@@ -50,14 +49,16 @@ def generate_ai_updates():
50
  return response['choices'][0]['message']['content']
51
 
52
  except Exception as e:
53
- # Return a cleaner message if API call fails
54
- print(f"Groq API error details: {e}")
 
 
55
  return "⚠️ Oops! Could not generate AI updates. Please try again later."
56
 
57
- # Gradio interface
58
  with gr.Blocks(title="AI Content Curator") as demo:
59
  gr.Markdown("# πŸ“ˆ AI Content Curator")
60
- gr.Markdown("Click the button below to generate the latest AI developments and recommendations using Gen AI.")
61
 
62
  with gr.Row():
63
  with gr.Column():
@@ -68,7 +69,7 @@ with gr.Blocks(title="AI Content Curator") as demo:
68
  label="πŸ”Ž AI Updates and Content Recommendations",
69
  lines=20,
70
  interactive=False,
71
- placeholder="Waiting for the latest AI trends..." # <-- Placeholder while loading
72
  )
73
 
74
  submit_btn.click(
@@ -77,6 +78,5 @@ with gr.Blocks(title="AI Content Curator") as demo:
77
  outputs=output
78
  )
79
 
80
- # Run app
81
  if __name__ == "__main__":
82
  demo.launch(share=True)
 
1
  import os
2
  import gradio as gr
3
+ import groq
4
  from dotenv import load_dotenv
5
  from datetime import datetime
6
 
7
  # Load environment variables
8
  load_dotenv()
9
 
10
+ # Set API Key for Groq globally
11
+ groq.api_key = os.getenv("GROQ_API_KEY")
12
+
13
  def load_system_prompt():
 
14
  try:
15
  current_dir = os.path.dirname(os.path.abspath(__file__))
16
  config_path = os.path.join(current_dir, "config", "system_prompt.txt")
 
17
  with open(config_path, 'r') as file:
18
  return file.read().strip()
19
  except Exception as e:
20
  print(f"Error loading system prompt: {str(e)}")
21
  return "You are a helpful social media research assistant."
22
 
 
23
  SYSTEM_PROMPT = load_system_prompt()
24
 
25
  def generate_ai_updates():
26
  """Generate AI updates using Groq API"""
27
  try:
28
  current_date = datetime.now().strftime("%B %d, %Y")
29
+
30
  response = groq.chat(
 
31
  messages=[
32
  {
33
  "role": "system",
 
35
  },
36
  {
37
  "role": "user",
38
+ "content": f"Please analyze and provide the latest AI developments and trends for {current_date}."
39
  }
40
  ],
41
  model="llama3-70b-8192",
 
49
  return response['choices'][0]['message']['content']
50
 
51
  except Exception as e:
52
+ import traceback
53
+ print("=== Full Groq API Error ===")
54
+ print(traceback.format_exc())
55
+ print("===========================")
56
  return "⚠️ Oops! Could not generate AI updates. Please try again later."
57
 
58
+ # Gradio app setup same as before
59
  with gr.Blocks(title="AI Content Curator") as demo:
60
  gr.Markdown("# πŸ“ˆ AI Content Curator")
61
+ gr.Markdown("Click to generate the latest AI developments and trends.")
62
 
63
  with gr.Row():
64
  with gr.Column():
 
69
  label="πŸ”Ž AI Updates and Content Recommendations",
70
  lines=20,
71
  interactive=False,
72
+ placeholder="Waiting for the latest AI trends..."
73
  )
74
 
75
  submit_btn.click(
 
78
  outputs=output
79
  )
80
 
 
81
  if __name__ == "__main__":
82
  demo.launch(share=True)