Spaces:
Sleeping
Sleeping
File size: 2,275 Bytes
9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd 4797a96 b44b64d 9a858fd b44b64d 9a858fd b44b64d 9a858fd b44b64d |
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 83 84 85 86 87 |
import streamlit as st
import requests
import os
# ------------------------
# Page Config
# ------------------------
st.set_page_config(
page_title="LinkedIn Post Generator",
page_icon="🚀"
)
st.title("🚀 AI LinkedIn Post Generator (Groq Powered)")
st.write("Generate high-engagement LinkedIn posts instantly.")
# ------------------------
# Load Groq API Key from Secrets
# ------------------------
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
if not GROQ_API_KEY:
st.error("Please add GROQ_API_KEY in Hugging Face Space Secrets.")
st.stop()
API_URL = "https://api.groq.com/openai/v1/chat/completions"
headers = {
"Authorization": f"Bearer {GROQ_API_KEY}",
"Content-Type": "application/json"
}
# ------------------------
# User Inputs
# ------------------------
topic = st.text_input("Enter Topic")
tone = st.selectbox(
"Select Tone",
["Professional", "Motivational", "Storytelling", "Bold", "Friendly"]
)
generate = st.button("Generate Post")
# ------------------------
# Generate Content
# ------------------------
if generate:
if not topic:
st.warning("Please enter a topic.")
else:
with st.spinner("Generating your post..."):
prompt = f"""
Write a high-engagement LinkedIn post about "{topic}".
Tone: {tone}
Requirements:
- Strong hook in first line
- Short readable paragraphs
- Add spacing for clarity
- End with an engaging question
- Include 3 relevant hashtags
"""
payload = {
"model": "llama-3.1-8b-instant",
"messages": [
{"role": "system", "content": "You are a LinkedIn content expert."},
{"role": "user", "content": prompt}
],
"temperature": 0.7,
"max_tokens": 500
}
response = requests.post(API_URL, headers=headers, json=payload)
if response.status_code == 200:
result = response.json()
content = result["choices"][0]["message"]["content"]
st.success("✅ Post Generated!")
st.text_area("Your LinkedIn Post", content, height=400)
else:
st.error("Error generating content.")
st.write(response.text)
|