DrishtiSharma commited on
Commit
9d12e16
Β·
verified Β·
1 Parent(s): f789a9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +115 -24
app.py CHANGED
@@ -1,42 +1,133 @@
1
  import streamlit as st
2
  from few_shot import FewShotPosts
3
  from post_generator import generate_post
 
4
 
5
-
6
- # Options for length and language
7
- length_options = ["Short", "Medium", "Long"]
8
- language_options = ["English", "Hinglish"]
9
-
10
-
11
- # Main app layout
12
  def main():
13
- st.subheader("LinkedIn Post Generator: Codebasics")
 
 
 
 
 
 
 
14
 
15
- # Create three columns for the dropdowns
16
- col1, col2, col3 = st.columns(3)
 
17
 
18
  fs = FewShotPosts()
19
  tags = fs.get_tags()
20
- with col1:
21
- # Dropdown for Topic (Tags)
22
- selected_tag = st.selectbox("Topic", options=tags)
23
 
24
- with col2:
25
- # Dropdown for Length
26
- selected_length = st.selectbox("Length", options=length_options)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
- with col3:
29
- # Dropdown for Language
30
- selected_language = st.selectbox("Language", options=language_options)
 
 
 
31
 
 
32
 
33
 
34
- # Generate Button
35
- if st.button("Generate"):
36
- post = generate_post(selected_length, selected_language, selected_tag)
37
- st.write(post)
 
 
 
 
 
38
 
39
 
40
  # Run the app
41
  if __name__ == "__main__":
42
- main()
 
1
  import streamlit as st
2
  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("πŸš€ Advanced 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()
 
 
 
23
 
24
+ # User input sections
25
+ st.sidebar.subheader("Post Preferences")
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
+ πŸ“ *Powered by OpenAI's ChatGroq and LangChain.*
92
+ πŸ“§ For feedback, contact: [[email protected]](mailto:[email protected])
93
+ """
94
+ )
95
+
96
+
97
+ def post_analysis(post):
98
+ """Perform basic analysis of the generated post."""
99
+ word_count = len(post.split())
100
+ char_count = len(post)
101
+ tone_keywords = {
102
+ "Motivational": ["inspire", "achieve", "goal", "success"],
103
+ "Professional": ["expertise", "career", "opportunity", "industry"],
104
+ "Informal": ["hey", "cool", "fun", "awesome"],
105
+ }
106
+
107
+ st.write(f"**Word Count:** {word_count}")
108
+ st.write(f"**Character Count:** {char_count}")
109
 
110
+ # Detect tone based on keywords (simple heuristic)
111
+ detected_tone = "Neutral"
112
+ for tone, keywords in tone_keywords.items():
113
+ if any(keyword in post.lower() for keyword in keywords):
114
+ detected_tone = tone
115
+ break
116
 
117
+ st.write(f"**Detected Tone:** {detected_tone}")
118
 
119
 
120
+ def download_posts(posts):
121
+ """Allow users to download their posts."""
122
+ posts_json = json.dumps(posts, indent=4)
123
+ st.download_button(
124
+ label="πŸ“₯ Download Posts",
125
+ data=posts_json,
126
+ file_name="generated_posts.json",
127
+ mime="application/json",
128
+ )
129
 
130
 
131
  # Run the app
132
  if __name__ == "__main__":
133
+ main()