Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from datetime import datetime
|
|
| 7 |
# Load environment variables
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
-
# Initialize Groq client
|
| 11 |
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
| 12 |
|
| 13 |
def load_system_prompt():
|
|
@@ -25,9 +25,11 @@ def load_system_prompt():
|
|
| 25 |
# Load system prompt once
|
| 26 |
SYSTEM_PROMPT = load_system_prompt()
|
| 27 |
|
| 28 |
-
def
|
| 29 |
-
"""Generate AI
|
| 30 |
try:
|
|
|
|
|
|
|
| 31 |
chat_completion = client.chat.completions.create(
|
| 32 |
messages=[
|
| 33 |
{
|
|
@@ -36,7 +38,7 @@ def generate_ai_content(user_topic):
|
|
| 36 |
},
|
| 37 |
{
|
| 38 |
"role": "user",
|
| 39 |
-
"content": f"
|
| 40 |
}
|
| 41 |
],
|
| 42 |
model="llama3-70b-8192",
|
|
@@ -53,33 +55,28 @@ def generate_ai_content(user_topic):
|
|
| 53 |
print("=== Groq API Error ===")
|
| 54 |
print(traceback.format_exc())
|
| 55 |
print("======================")
|
| 56 |
-
return "β οΈ Oops! Could not generate AI
|
| 57 |
|
| 58 |
# Gradio app
|
| 59 |
with gr.Blocks(title="AI Content Curator") as demo:
|
| 60 |
gr.Markdown("# π AI Content Curator")
|
| 61 |
-
gr.Markdown("
|
| 62 |
|
| 63 |
with gr.Row():
|
| 64 |
with gr.Column():
|
| 65 |
-
|
| 66 |
-
label="Enter your topic or idea",
|
| 67 |
-
placeholder="e.g., OpenAI's GPT-5 launch, AI use in healthcare...",
|
| 68 |
-
lines=2
|
| 69 |
-
)
|
| 70 |
-
submit_btn = gr.Button("π Generate AI Content")
|
| 71 |
|
| 72 |
with gr.Column():
|
| 73 |
output = gr.Textbox(
|
| 74 |
-
label="
|
| 75 |
-
lines=
|
| 76 |
interactive=False,
|
| 77 |
-
placeholder="
|
| 78 |
)
|
| 79 |
|
| 80 |
submit_btn.click(
|
| 81 |
-
fn=
|
| 82 |
-
inputs=[
|
| 83 |
outputs=output
|
| 84 |
)
|
| 85 |
|
|
|
|
| 7 |
# Load environment variables
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
+
# Initialize Groq client properly
|
| 11 |
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
|
| 12 |
|
| 13 |
def load_system_prompt():
|
|
|
|
| 25 |
# Load system prompt once
|
| 26 |
SYSTEM_PROMPT = load_system_prompt()
|
| 27 |
|
| 28 |
+
def generate_ai_updates():
|
| 29 |
+
"""Generate AI updates using Groq API."""
|
| 30 |
try:
|
| 31 |
+
current_date = datetime.now().strftime("%B %d, %Y")
|
| 32 |
+
|
| 33 |
chat_completion = client.chat.completions.create(
|
| 34 |
messages=[
|
| 35 |
{
|
|
|
|
| 38 |
},
|
| 39 |
{
|
| 40 |
"role": "user",
|
| 41 |
+
"content": f"Please analyze and provide the latest AI developments and trends for {current_date}. Follow the verification workflow and create content as specified."
|
| 42 |
}
|
| 43 |
],
|
| 44 |
model="llama3-70b-8192",
|
|
|
|
| 55 |
print("=== Groq API Error ===")
|
| 56 |
print(traceback.format_exc())
|
| 57 |
print("======================")
|
| 58 |
+
return "β οΈ Oops! Could not generate AI updates. Please try again later."
|
| 59 |
|
| 60 |
# Gradio app
|
| 61 |
with gr.Blocks(title="AI Content Curator") as demo:
|
| 62 |
gr.Markdown("# π AI Content Curator")
|
| 63 |
+
gr.Markdown("Click below to generate the latest AI developments and recommendations.")
|
| 64 |
|
| 65 |
with gr.Row():
|
| 66 |
with gr.Column():
|
| 67 |
+
submit_btn = gr.Button("π Generate Latest AI Updates")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
with gr.Column():
|
| 70 |
output = gr.Textbox(
|
| 71 |
+
label="π AI Updates and Content Recommendations",
|
| 72 |
+
lines=20,
|
| 73 |
interactive=False,
|
| 74 |
+
placeholder="Waiting for AI updates..."
|
| 75 |
)
|
| 76 |
|
| 77 |
submit_btn.click(
|
| 78 |
+
fn=generate_ai_updates,
|
| 79 |
+
inputs=[],
|
| 80 |
outputs=output
|
| 81 |
)
|
| 82 |
|