Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,34 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
-
import base64
|
| 6 |
from datetime import datetime
|
| 7 |
|
| 8 |
# Load environment variables
|
| 9 |
load_dotenv()
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
client = Groq(api_key=os.getenv("GROQ_API_KEY"), http_client=None)
|
| 13 |
|
| 14 |
def load_system_prompt():
|
| 15 |
-
"""Load and decode the system prompt from the config file"""
|
| 16 |
try:
|
| 17 |
-
# Get the directory of the current script
|
| 18 |
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 19 |
config_path = os.path.join(current_dir, "config", "system_prompt.txt")
|
| 20 |
-
|
| 21 |
-
# Read the system prompt
|
| 22 |
with open(config_path, 'r') as file:
|
| 23 |
return file.read().strip()
|
| 24 |
except Exception as e:
|
| 25 |
print(f"Error loading system prompt: {str(e)}")
|
| 26 |
return "You are a helpful social media research assistant."
|
| 27 |
|
| 28 |
-
# Load
|
| 29 |
SYSTEM_PROMPT = load_system_prompt()
|
| 30 |
|
| 31 |
def generate_ai_updates():
|
| 32 |
"""Generate AI updates using Groq API"""
|
| 33 |
try:
|
| 34 |
-
# Get current date for context
|
| 35 |
current_date = datetime.now().strftime("%B %d, %Y")
|
| 36 |
|
| 37 |
-
|
|
|
|
| 38 |
messages=[
|
| 39 |
{
|
| 40 |
"role": "system",
|
|
@@ -42,7 +36,7 @@ def generate_ai_updates():
|
|
| 42 |
},
|
| 43 |
{
|
| 44 |
"role": "user",
|
| 45 |
-
"content": f"Please analyze and provide the latest AI developments and trends for {current_date}.
|
| 46 |
}
|
| 47 |
],
|
| 48 |
model="llama3-70b-8192",
|
|
@@ -52,14 +46,15 @@ def generate_ai_updates():
|
|
| 52 |
frequency_penalty=0.1,
|
| 53 |
presence_penalty=0.1
|
| 54 |
)
|
| 55 |
-
return
|
|
|
|
| 56 |
except Exception as e:
|
| 57 |
return f"Error: {str(e)}"
|
| 58 |
|
| 59 |
-
#
|
| 60 |
with gr.Blocks(title="AI Content Curator") as demo:
|
| 61 |
gr.Markdown("# AI Content Curator")
|
| 62 |
-
gr.Markdown("Click
|
| 63 |
|
| 64 |
with gr.Row():
|
| 65 |
with gr.Column():
|
|
@@ -79,4 +74,4 @@ with gr.Blocks(title="AI Content Curator") as demo:
|
|
| 79 |
)
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
| 82 |
-
demo.launch(share=True)
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
import groq # <--- Just import groq directly
|
| 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 at app startup
|
| 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.ChatCompletion.create( # <--- Directly calling groq.ChatCompletion.create
|
| 31 |
+
api_key=os.getenv("GROQ_API_KEY"), # <--- Pass API key here instead
|
| 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}."
|
| 40 |
}
|
| 41 |
],
|
| 42 |
model="llama3-70b-8192",
|
|
|
|
| 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 |
return f"Error: {str(e)}"
|
| 53 |
|
| 54 |
+
# Gradio UI as you had it
|
| 55 |
with gr.Blocks(title="AI Content Curator") as demo:
|
| 56 |
gr.Markdown("# AI Content Curator")
|
| 57 |
+
gr.Markdown("Click to get the latest AI developments and recommendations.")
|
| 58 |
|
| 59 |
with gr.Row():
|
| 60 |
with gr.Column():
|
|
|
|
| 74 |
)
|
| 75 |
|
| 76 |
if __name__ == "__main__":
|
| 77 |
+
demo.launch(share=True)
|