File size: 1,577 Bytes
2811f8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import gradio as gr
from groq import Groq

# Fetch the key from Hugging Face Secrets
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
client = Groq(api_key=GROQ_API_KEY)

def generate_linkedin_post(topic, tone):
    # Using the updated Llama 3.1 model
    model_name = "llama-3.1-8b-instant" 
    
    prompt = f"Write a professional LinkedIn post about '{topic}'. The tone should be {tone}. Include relevant emojis and 3-5 hashtags."
    
    try:
        completion = client.chat.completions.create(
            model=model_name,
            messages=[
                {"role": "system", "content": "You are an expert content creator for LinkedIn."},
                {"role": "user", "content": prompt}
            ],
            temperature=0.7,
            max_tokens=1024,
        )
        return completion.choices[0].message.content
    except Exception as e:
        return f"Error: {str(e)}"

# UI Design
with gr.Blocks() as demo:
    gr.Markdown("# 🚀 AI LinkedIn Post Generator")
    with gr.Row():
        topic_input = gr.Textbox(label="What is the post about?")
        tone_input = gr.Dropdown(
            choices=["Professional", "Inspirational", "Witty", "Educational"], 
            value="Professional", 
            label="Tone"
        )
    generate_btn = gr.Button("Generate Post", variant="primary")
    output_text = gr.Textbox(label="Generated Post", lines=10)
    
    generate_btn.click(fn=generate_linkedin_post, inputs=[topic_input, tone_input], outputs=output_text)

# Launch (Hugging Face handles the port automatically)
demo.launch()