Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,25 @@
|
|
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 |
-
# (No Groq client needed here!)
|
11 |
-
|
12 |
def load_system_prompt():
|
|
|
13 |
try:
|
14 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
15 |
config_path = os.path.join(current_dir, "config", "system_prompt.txt")
|
|
|
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 system prompt
|
23 |
SYSTEM_PROMPT = load_system_prompt()
|
24 |
|
25 |
def generate_ai_updates():
|
@@ -27,8 +27,8 @@ def generate_ai_updates():
|
|
27 |
try:
|
28 |
current_date = datetime.now().strftime("%B %d, %Y")
|
29 |
|
30 |
-
response = groq.
|
31 |
-
api_key=os.getenv("GROQ_API_KEY"),
|
32 |
messages=[
|
33 |
{
|
34 |
"role": "system",
|
@@ -36,7 +36,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}."
|
40 |
}
|
41 |
],
|
42 |
model="llama3-70b-8192",
|
@@ -46,25 +46,29 @@ def generate_ai_updates():
|
|
46 |
frequency_penalty=0.1,
|
47 |
presence_penalty=0.1
|
48 |
)
|
|
|
49 |
return response['choices'][0]['message']['content']
|
50 |
|
51 |
except Exception as e:
|
52 |
-
|
|
|
|
|
53 |
|
54 |
-
# Gradio
|
55 |
with gr.Blocks(title="AI Content Curator") as demo:
|
56 |
-
gr.Markdown("# AI Content Curator")
|
57 |
-
gr.Markdown("Click to
|
58 |
-
|
59 |
with gr.Row():
|
60 |
with gr.Column():
|
61 |
-
submit_btn = gr.Button("Generate Latest AI Updates")
|
62 |
|
63 |
with gr.Column():
|
64 |
output = gr.Textbox(
|
65 |
-
label="AI Updates and Content Recommendations",
|
66 |
lines=20,
|
67 |
-
interactive=False
|
|
|
68 |
)
|
69 |
|
70 |
submit_btn.click(
|
@@ -73,5 +77,6 @@ with gr.Blocks(title="AI Content Curator") as demo:
|
|
73 |
outputs=output
|
74 |
)
|
75 |
|
|
|
76 |
if __name__ == "__main__":
|
77 |
demo.launch(share=True)
|
|
|
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():
|
|
|
27 |
try:
|
28 |
current_date = datetime.now().strftime("%B %d, %Y")
|
29 |
|
30 |
+
response = groq.chat(
|
31 |
+
api_key=os.getenv("GROQ_API_KEY"),
|
32 |
messages=[
|
33 |
{
|
34 |
"role": "system",
|
|
|
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",
|
|
|
46 |
frequency_penalty=0.1,
|
47 |
presence_penalty=0.1
|
48 |
)
|
49 |
+
|
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"Error during AI generation: {str(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():
|
64 |
+
submit_btn = gr.Button("🚀 Generate Latest AI Updates")
|
65 |
|
66 |
with gr.Column():
|
67 |
output = gr.Textbox(
|
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 |
outputs=output
|
78 |
)
|
79 |
|
80 |
+
# Run app
|
81 |
if __name__ == "__main__":
|
82 |
demo.launch(share=True)
|