0o7Hunk commited on
Commit
092bf98
·
verified ·
1 Parent(s): 37963bb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from groq import Groq
3
+ import os
4
+
5
+ # ---- PAGE CONFIG ----
6
+ st.set_page_config(page_title="AI LinkedIn Post Generator", page_icon="💼")
7
+
8
+ st.title("💼 AI LinkedIn Post Generator")
9
+ st.write("Generate high-quality LinkedIn posts using AI 🚀")
10
+
11
+ # ---- API KEY INPUT ----
12
+ api_key = st.text_input("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", type="password")
13
+
14
+ # ---- USER INPUTS ----
15
+ tone = st.radio(
16
+ "Select Post Tone:",
17
+ ["Professional", "Casual", "Motivational", "Storytelling"]
18
+ )
19
+
20
+ topic = st.text_input("Enter your topic")
21
+ audience = st.text_input("Target audience (e.g. students, developers)")
22
+
23
+ # ---- GENERATE BUTTON ----
24
+ if st.button("Generate Post"):
25
+
26
+ if not api_key:
27
+ st.error("Please enter your Groq API key")
28
+ elif not topic or not audience:
29
+ st.error("Please fill all fields")
30
+ else:
31
+ try:
32
+ # Initialize client
33
+ client = Groq(api_key=api_key)
34
+
35
+ # Prompt
36
+ prompt = f"""
37
+ Write a LinkedIn post.
38
+
39
+ Topic: {topic}
40
+ Audience: {audience}
41
+ Tone: {tone}
42
+
43
+ Make it:
44
+ - Engaging and scroll-stopping
45
+ - Include a strong hook
46
+ - Well-structured body
47
+ - End with a call-to-action (CTA)
48
+ - Use emojis and spacing
49
+ - Add relevant hashtags
50
+ """
51
+
52
+ # API call
53
+ response = client.chat.completions.create(
54
+ model="openai/gpt-oss-120b", # Safe model
55
+ messages=[{"role": "user", "content": prompt}],
56
+ temperature=0.7,
57
+ max_tokens=500
58
+ )
59
+
60
+ post = response.choices[0].message.content
61
+
62
+ # Output
63
+ st.subheader("📄 Generated Post")
64
+ st.write(post)
65
+
66
+ # Copy option
67
+ st.code(post)
68
+
69
+ except Exception as e:
70
+ st.error(f"Error: {str(e)}")