Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,142 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from agents import web_summarizer_company, web_summarizer_person, company_linkedin_agent, person_linkedin_agent
|
| 3 |
-
from tools import scrape_website, post_on_linkedin, replace_i_with_you
|
| 4 |
-
|
| 5 |
-
def main():
|
| 6 |
-
st.title('LinkedIn Post Generator')
|
| 7 |
-
|
| 8 |
-
with st.form(key='linkedin_form'):
|
| 9 |
-
topic = st.text_input('Topic')
|
| 10 |
-
url = st.text_input('Website URL')
|
| 11 |
-
mood = st.text_input('Mood')
|
| 12 |
-
post_company = st.checkbox('For Company')
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
post_content
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
st.
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from agents import web_summarizer_company, web_summarizer_person, company_linkedin_agent, person_linkedin_agent, image_prompt_agent
|
| 3 |
+
from tools import scrape_website, post_on_linkedin, replace_i_with_you, generate_image
|
| 4 |
+
|
| 5 |
+
def main():
|
| 6 |
+
st.title('LinkedIn Post Generator')
|
| 7 |
+
|
| 8 |
+
with st.form(key='linkedin_form'):
|
| 9 |
+
topic = st.text_input('Topic')
|
| 10 |
+
url = st.text_input('Website URL')
|
| 11 |
+
mood = st.text_input('Mood')
|
| 12 |
+
post_company = st.checkbox('For Company')
|
| 13 |
+
ai_image = st.checkbox('Add AI Generated Image')
|
| 14 |
+
|
| 15 |
+
generate_button = st.form_submit_button(label='Generate Post')
|
| 16 |
+
|
| 17 |
+
if generate_button:
|
| 18 |
+
if url:
|
| 19 |
+
|
| 20 |
+
scraped_data = scrape_website(url)
|
| 21 |
+
|
| 22 |
+
if post_company:
|
| 23 |
+
summary = web_summarizer_company(scraped_data)
|
| 24 |
+
else:
|
| 25 |
+
summary = web_summarizer_person(scraped_data)
|
| 26 |
+
summary = replace_i_with_you(summary.content)
|
| 27 |
+
print(summary)
|
| 28 |
+
|
| 29 |
+
if post_company:
|
| 30 |
+
post_content = company_linkedin_agent(topic, summary, mood)
|
| 31 |
+
else:
|
| 32 |
+
post_content = person_linkedin_agent(topic, summary, mood)
|
| 33 |
+
|
| 34 |
+
print(post_content.content)
|
| 35 |
+
post_content = post_content.content
|
| 36 |
+
|
| 37 |
+
if post_content.endswith(':'):
|
| 38 |
+
post_content = post_content[:-5]
|
| 39 |
+
|
| 40 |
+
image_path = None
|
| 41 |
+
if ai_image:
|
| 42 |
+
prompt = image_prompt_agent(post_content)
|
| 43 |
+
image_path = generate_image(prompt)
|
| 44 |
+
print(image_path)
|
| 45 |
+
|
| 46 |
+
st.session_state.post_content = post_content
|
| 47 |
+
st.session_state.image_path = image_path
|
| 48 |
+
st.session_state.post_generated = True
|
| 49 |
+
|
| 50 |
+
st.markdown(f"**Generated Post Content:**\n\n{st.session_state.post_content}")
|
| 51 |
+
if ai_image:
|
| 52 |
+
st.image(image_path)
|
| 53 |
+
|
| 54 |
+
# Text area for reviewing generated content
|
| 55 |
+
# st.text_area('Post Content (for review)', st.session_state.post_content, height=200)
|
| 56 |
+
|
| 57 |
+
else:
|
| 58 |
+
st.error('Please provide a URL.')
|
| 59 |
+
|
| 60 |
+
# Button to post on LinkedIn outside the form
|
| 61 |
+
if st.session_state.get('post_generated'):
|
| 62 |
+
post_linkedin = st.checkbox('Post on LinkedIn')
|
| 63 |
+
|
| 64 |
+
if post_linkedin:
|
| 65 |
+
token = st.text_input('LinkedIn Token', type='password')
|
| 66 |
+
post_button = st.button('Post')
|
| 67 |
+
if post_button:
|
| 68 |
+
image_path = st.session_state.image_path
|
| 69 |
+
post_on_linkedin(token, 'linkedin post', st.session_state.post_content, image_path)
|
| 70 |
+
st.success('Post has been successfully published on LinkedIn!')
|
| 71 |
+
st.session_state.post_generated = False # Reset state after posting
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
main()
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
# import streamlit as st
|
| 80 |
+
# from agents import web_summarizer_company, web_summarizer_person, company_linkedin_agent, person_linkedin_agent
|
| 81 |
+
# from tools import scrape_website, post_on_linkedin, replace_i_with_you
|
| 82 |
+
|
| 83 |
+
# def main():
|
| 84 |
+
# st.title('LinkedIn Post Generator')
|
| 85 |
+
|
| 86 |
+
# with st.form(key='linkedin_form'):
|
| 87 |
+
# topic = st.text_input('Topic')
|
| 88 |
+
# url = st.text_input('Website URL')
|
| 89 |
+
# mood = st.text_input('Mood')
|
| 90 |
+
# post_company = st.checkbox('For Company')
|
| 91 |
+
|
| 92 |
+
# generate_button = st.form_submit_button(label='Generate Post')
|
| 93 |
+
|
| 94 |
+
# if generate_button:
|
| 95 |
+
# if url:
|
| 96 |
+
|
| 97 |
+
# scraped_data = scrape_website(url)
|
| 98 |
+
|
| 99 |
+
# if post_company:
|
| 100 |
+
# summary = web_summarizer_company(scraped_data)
|
| 101 |
+
# else:
|
| 102 |
+
# summary = web_summarizer_person(scraped_data)
|
| 103 |
+
# summary = replace_i_with_you(summary.content)
|
| 104 |
+
# print(summary)
|
| 105 |
+
|
| 106 |
+
# if post_company:
|
| 107 |
+
# post_content = company_linkedin_agent(topic, summary, mood)
|
| 108 |
+
# else:
|
| 109 |
+
# post_content = person_linkedin_agent(topic, summary, mood)
|
| 110 |
+
|
| 111 |
+
# print(post_content.content)
|
| 112 |
+
# post_content = post_content.content
|
| 113 |
+
|
| 114 |
+
# if post_content.endswith(':'):
|
| 115 |
+
# post_content = post_content[:-5]
|
| 116 |
+
|
| 117 |
+
# st.session_state.post_content = post_content
|
| 118 |
+
# st.session_state.post_generated = True
|
| 119 |
+
|
| 120 |
+
# st.markdown(f"**Generated Post Content:**\n\n{st.session_state.post_content}")
|
| 121 |
+
|
| 122 |
+
# # Text area for reviewing generated content
|
| 123 |
+
# # st.text_area('Post Content (for review)', st.session_state.post_content, height=200)
|
| 124 |
+
|
| 125 |
+
# else:
|
| 126 |
+
# st.error('Please provide a URL.')
|
| 127 |
+
|
| 128 |
+
# # Button to post on LinkedIn outside the form
|
| 129 |
+
# if st.session_state.get('post_generated'):
|
| 130 |
+
# post_linkedin = st.checkbox('Post on LinkedIn')
|
| 131 |
+
|
| 132 |
+
# if post_linkedin:
|
| 133 |
+
# token = st.text_input('LinkedIn Token', type='password')
|
| 134 |
+
# post_button = st.button('Post')
|
| 135 |
+
# if post_button:
|
| 136 |
+
# image_path = None
|
| 137 |
+
# post_on_linkedin(token, 'linkedin post', st.session_state.post_content, image_path)
|
| 138 |
+
# st.success('Post has been successfully published on LinkedIn!')
|
| 139 |
+
# st.session_state.post_generated = False # Reset state after posting
|
| 140 |
+
|
| 141 |
+
# if __name__ == "__main__":
|
| 142 |
+
# main()
|