DrishtiSharma commited on
Commit
20dfeac
Β·
verified Β·
1 Parent(s): 115b957

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -74
app.py CHANGED
@@ -3,20 +3,15 @@ from few_shot import FewShotPosts
3
  from post_generator import generate_post
4
  import json
5
 
6
- # Improved app with more functionality
7
  def main():
8
  st.set_page_config(page_title="LinkedIn Post Generator", layout="wide")
9
  st.title("πŸš€ LinkedIn Post Generator")
10
- st.markdown(
11
- """
12
- **Create impactful LinkedIn posts effortlessly.**
13
- Customize your post with advanced options, analyze generated content, and save your creations.
14
- """
15
- )
16
 
17
- # Sidebar for advanced options
18
  st.sidebar.title("πŸ”§ Customization Options")
19
- st.sidebar.markdown("Use these settings to personalize your generated post.")
20
 
21
  fs = FewShotPosts()
22
  tags = fs.get_tags()
@@ -26,71 +21,82 @@ def main():
26
  selected_tag = st.sidebar.selectbox("Topic (Tag):", options=tags)
27
  selected_length = st.sidebar.radio("Post Length:", ["Short", "Medium", "Long"])
28
  selected_language = st.sidebar.radio("Language:", ["English", "Hinglish"])
29
- selected_tone = st.sidebar.selectbox(
30
- "Tone/Style:", ["Motivational", "Professional", "Informal", "Neutral"]
31
- )
32
- custom_context = st.sidebar.text_area(
33
- "Additional Context (Optional):",
34
- placeholder="Provide extra details or a specific direction for your post...",
35
- )
36
 
37
- # History tracking
38
  if "generated_posts" not in st.session_state:
39
  st.session_state.generated_posts = []
40
 
41
- # Main content
42
- st.subheader("Generate Your LinkedIn Post")
43
-
44
- if st.button("Generate Post"):
45
- with st.spinner("Generating your post..."):
46
- try:
47
- # Generate post
48
- post = generate_post(selected_length, selected_language, selected_tag)
49
-
50
- # Add tone and context to the prompt dynamically
51
- if selected_tone:
52
- post = f"**Tone**: {selected_tone}\n\n{post}"
53
- if custom_context:
54
- post += f"\n\n**Context Added**: {custom_context}"
55
-
56
- # Save to session history
57
- st.session_state.generated_posts.append(post)
58
-
59
- st.success("Post generated successfully!")
60
- st.markdown("### Your LinkedIn Post:")
61
- st.write(post)
62
-
63
- # Post analysis
64
- st.markdown("### Post Analysis:")
65
- post_analysis(post)
66
-
67
- except Exception as e:
68
- st.error(f"An error occurred: {e}")
69
-
70
- # Display session history
71
- if st.session_state.generated_posts:
72
- st.markdown("### Generated Posts History:")
73
- for i, history_post in enumerate(st.session_state.generated_posts):
74
- st.markdown(f"**Post {i + 1}:**")
75
- st.write(history_post)
76
-
77
- # Save and Download
78
- st.markdown("---")
79
- st.subheader("Save or Share Your Post")
80
- if st.session_state.generated_posts:
81
- if st.button("Download All Posts"):
82
- download_posts(st.session_state.generated_posts)
83
- if st.button("Clear History"):
84
- st.session_state.generated_posts = []
85
- st.info("History cleared!")
86
-
87
- # Footer
88
- st.markdown(
89
- """
90
- ---
91
- """
92
- )
93
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  def post_analysis(post):
96
  """Perform basic analysis of the generated post."""
@@ -102,8 +108,8 @@ def post_analysis(post):
102
  "Informal": ["hey", "cool", "fun", "awesome"],
103
  }
104
 
105
- st.write(f"**Word Count:** {word_count}")
106
- st.write(f"**Character Count:** {char_count}")
107
 
108
  # Detect tone based on keywords (simple heuristic)
109
  detected_tone = "Neutral"
@@ -112,7 +118,7 @@ def post_analysis(post):
112
  detected_tone = tone
113
  break
114
 
115
- st.write(f"**Detected Tone:** {detected_tone}")
116
 
117
 
118
  def download_posts(posts):
@@ -126,6 +132,5 @@ def download_posts(posts):
126
  )
127
 
128
 
129
- # Run the app
130
  if __name__ == "__main__":
131
  main()
 
3
  from post_generator import generate_post
4
  import json
5
 
6
+
7
  def main():
8
  st.set_page_config(page_title="LinkedIn Post Generator", layout="wide")
9
  st.title("πŸš€ LinkedIn Post Generator")
10
+ st.markdown("**Create impactful LinkedIn posts effortlessly.** Customize your post with advanced options, analyze generated content, and save your creations.")
 
 
 
 
 
11
 
12
+ # Sidebar for settings
13
  st.sidebar.title("πŸ”§ Customization Options")
14
+ st.sidebar.markdown("Use these settings to personalize your post.")
15
 
16
  fs = FewShotPosts()
17
  tags = fs.get_tags()
 
21
  selected_tag = st.sidebar.selectbox("Topic (Tag):", options=tags)
22
  selected_length = st.sidebar.radio("Post Length:", ["Short", "Medium", "Long"])
23
  selected_language = st.sidebar.radio("Language:", ["English", "Hinglish"])
24
+ selected_tone = st.sidebar.selectbox("Tone/Style:", ["Motivational", "Professional", "Informal", "Neutral"])
25
+ custom_context = st.sidebar.text_area("Additional Context (Optional):", placeholder="Provide extra details...")
 
 
 
 
 
26
 
27
+ # Initialize session state
28
  if "generated_posts" not in st.session_state:
29
  st.session_state.generated_posts = []
30
 
31
+ # Tabs for different modes
32
+ tabs = st.tabs(["Generate Post", "Edit Post", "Analyze Post", "History", "Save/Share"])
33
+
34
+ # Tab 1: Generate Post
35
+ with tabs[0]:
36
+ st.subheader("Create a Post")
37
+ if st.button("Generate Post"):
38
+ with st.spinner("Generating your post..."):
39
+ try:
40
+ post = generate_post(selected_length, selected_language, selected_tag, selected_tone)
41
+
42
+ # Add tone and context dynamically
43
+ if selected_tone:
44
+ post = f"**Tone**: {selected_tone}\n\n{post}"
45
+ if custom_context:
46
+ post += f"\n\n**Additional Context**: {custom_context}"
47
+
48
+ # Save to session history
49
+ st.session_state.generated_posts.append(post)
50
+ st.success("Post generated successfully!")
51
+ st.markdown("### Your LinkedIn Post:")
52
+ st.markdown(f"<div style='background-color: #f9f9f9; padding: 10px; border-radius: 5px;'>{post}</div>", unsafe_allow_html=True)
53
+
54
+ except Exception as e:
55
+ st.error(f"An error occurred: {e}")
56
+
57
+ # Tab 2: Edit Post
58
+ with tabs[1]:
59
+ st.subheader("Edit Your Post")
60
+ if st.session_state.generated_posts:
61
+ editable_post = st.text_area("Edit your post:", st.session_state.generated_posts[-1])
62
+ if st.button("Save Changes"):
63
+ st.session_state.generated_posts[-1] = editable_post
64
+ st.success("Post updated!")
65
+ else:
66
+ st.info("Generate a post to edit.")
67
+
68
+ # Tab 3: Analyze Post
69
+ with tabs[2]:
70
+ st.subheader("Analyze Your Post")
71
+ if st.session_state.generated_posts:
72
+ post_to_analyze = st.session_state.generated_posts[-1]
73
+ st.markdown("### Post for Analysis:")
74
+ st.write(post_to_analyze)
75
+ post_analysis(post_to_analyze)
76
+ else:
77
+ st.info("Generate a post to analyze.")
78
+
79
+ # Tab 4: Post History
80
+ with tabs[3]:
81
+ st.subheader("Generated Posts History")
82
+ if st.session_state.generated_posts:
83
+ for i, post in enumerate(reversed(st.session_state.generated_posts), start=1):
84
+ with st.expander(f"Post {i}"):
85
+ st.write(post)
86
+ else:
87
+ st.info("No posts generated yet.")
88
+
89
+ # Tab 5: Save or Share
90
+ with tabs[4]:
91
+ st.subheader("Save or Share Your Post")
92
+ if st.session_state.generated_posts:
93
+ if st.button("Download All Posts"):
94
+ download_posts(st.session_state.generated_posts)
95
+ if st.button("Clear History"):
96
+ st.session_state.generated_posts = []
97
+ st.info("History cleared!")
98
+ else:
99
+ st.info("No posts to save or share.")
100
 
101
  def post_analysis(post):
102
  """Perform basic analysis of the generated post."""
 
108
  "Informal": ["hey", "cool", "fun", "awesome"],
109
  }
110
 
111
+ st.metric("Word Count", word_count)
112
+ st.metric("Character Count", char_count)
113
 
114
  # Detect tone based on keywords (simple heuristic)
115
  detected_tone = "Neutral"
 
118
  detected_tone = tone
119
  break
120
 
121
+ st.metric("Detected Tone", detected_tone)
122
 
123
 
124
  def download_posts(posts):
 
132
  )
133
 
134
 
 
135
  if __name__ == "__main__":
136
  main()