Spaces:
Sleeping
Sleeping
File size: 9,140 Bytes
d8e2132 154c276 d8e2132 154c276 d8e2132 154c276 d8e2132 154c276 d8e2132 154c276 d8e2132 154c276 d8e2132 154c276 d8e2132 154c276 d8e2132 154c276 d8e2132 |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
import streamlit as st
from agents import web_summarizer_company, web_summarizer_person, company_linkedin_agent, person_linkedin_agent, image_prompt_agent, tweet_agent
from tools import scrape_website, post_on_linkedin, generate_image, post_on_twitter
def main():
st.title('Social Media Content Generator')
tab1, tab2 = st.tabs(["LinkedIn", "Twitter"])
with tab1:
with st.form(key='linkedin_form'):
topic = st.text_input('Topic')
url = st.text_input('Website URL')
mood = st.text_input('Mood')
post_company = st.checkbox('For Company')
ai_image = st.checkbox('Add AI Generated Image')
generate_button = st.form_submit_button(label='Generate Post')
if generate_button:
if url:
try:
scraped_data = scrape_website(url)
if scrape_website == '':
scraped_data = 'scrape failed'
except Exception as e:
st.error('unable to scrape website')
if scraped_data == 'scrape failed':
summary = 'summary not available'
else:
if post_company:
summary = web_summarizer_company(scraped_data)
else:
print(1111)
summary = web_summarizer_person(scraped_data)
print(summary)
try:
summary = summary.content
except Exception as e:
print(e)
print('summary: ' + summary)
if post_company:
post_content = company_linkedin_agent(topic, summary, mood)
else:
post_content = person_linkedin_agent(topic, summary, mood)
print(post_content.content)
post_content = post_content.content
if post_content.endswith(':'):
post_content = post_content[:-5]
image_path = None
if ai_image:
prompt = image_prompt_agent(post_content)
print(prompt.content)
image_path = generate_image(prompt.content)
print(image_path)
st.session_state.post_content = post_content
st.session_state.image_path = image_path
st.session_state.post_generated = True
st.markdown(f"**Generated Post Content:**\n\n{st.session_state.post_content}")
if ai_image:
st.image(image_path)
# Text area for reviewing generated content
# st.text_area('Post Content (for review)', st.session_state.post_content, height=200)
else:
st.error('Something went wrong.')
# Button to post on LinkedIn outside the form
if st.session_state.get('post_generated'):
post_linkedin = st.checkbox('Post on LinkedIn')
if post_linkedin:
token = st.text_input('LinkedIn Token', type='password')
post_button = st.button('Post')
if post_button:
image_path = st.session_state.image_path
post_on_linkedin(token, 'linkedin post', st.session_state.post_content, image_path)
st.success('Post has been successfully published on LinkedIn!')
st.session_state.post_generated = False # Reset state after posting
with tab2:
with st.form(key='twitter_form'):
topic = st.text_input('Topic')
# url = st.text_input('Website URL')
instructions = st.text_area('Instructions')
mood = st.text_input('Mood')
# post_company = st.checkbox('For Company')
# ai_image = st.checkbox('Add AI Generated Image')
generate_button = st.form_submit_button(label='Generate Post')
if generate_button:
tweet_content = tweet_agent(topic, instructions, mood)
st.session_state.tweet_content = tweet_content.content.strip('"')
st.session_state.tweet_generated = True
st.markdown(f"**Generated tweet:**\n\n{st.session_state.tweet_content}")
if st.session_state.get('tweet_generated'):
post_twitter = st.checkbox('Post on Twitter')
if post_twitter:
consumer_key = st.text_input(label='', placeholder='consumer key')
consumer_secret = st.text_input(label='', placeholder='consumer secret')
access_token = st.text_input(label='', placeholder='access token')
access_token_secret = st.text_input(label='', placeholder='access token secret')
post_button = st.button('Post')
if post_button:
# post_on_twitter(token, 'linkedin post', st.session_state.post_content, image_path)
if consumer_key and consumer_secret and access_token and access_token_secret:
post_on_twitter(st.session_state.tweet_content, consumer_key, consumer_secret, access_token, access_token_secret)
else:
st.error('Enter credentials!')
st.success('Post has been successfully published on Twitter!')
st.session_state.post_generated = False # Reset state after posting
if __name__ == "__main__":
main()
# import streamlit as st
# from agents import web_summarizer_company, web_summarizer_person, company_linkedin_agent, person_linkedin_agent, image_prompt_agent
# from tools import scrape_website, post_on_linkedin, replace_i_with_you, generate_image
# def main():
# st.title('LinkedIn Post Generator')
# with st.form(key='linkedin_form'):
# topic = st.text_input('Topic')
# url = st.text_input('Website URL')
# mood = st.text_input('Mood')
# post_company = st.checkbox('For Company')
# ai_image = st.checkbox('Add AI Generated Image')
# generate_button = st.form_submit_button(label='Generate Post')
# if generate_button:
# if url:
# try:
# scraped_data = scrape_website(url)
# except Exception as e:
# st.error('unable to scrape website')
# if post_company:
# summary = web_summarizer_company(scraped_data)
# else:
# summary = web_summarizer_person(scraped_data)
# summary = replace_i_with_you(summary.content)
# print(summary)
# if post_company:
# post_content = company_linkedin_agent(topic, summary, mood)
# else:
# post_content = person_linkedin_agent(topic, summary, mood)
# print(post_content.content)
# post_content = post_content.content
# if post_content.endswith(':'):
# post_content = post_content[:-5]
# image_path = None
# if ai_image:
# prompt = image_prompt_agent(post_content)
# print(prompt.content)
# image_path = generate_image(prompt.content)
# print(image_path)
# st.session_state.post_content = post_content
# st.session_state.image_path = image_path
# st.session_state.post_generated = True
# st.markdown(f"**Generated Post Content:**\n\n{st.session_state.post_content}")
# if ai_image:
# st.image(image_path)
# # Text area for reviewing generated content
# # st.text_area('Post Content (for review)', st.session_state.post_content, height=200)
# else:
# st.error('Please provide a URL.')
# # Button to post on LinkedIn outside the form
# if st.session_state.get('post_generated'):
# post_linkedin = st.checkbox('Post on LinkedIn')
# if post_linkedin:
# token = st.text_input('LinkedIn Token', type='password')
# post_button = st.button('Post')
# if post_button:
# image_path = st.session_state.image_path
# post_on_linkedin(token, 'linkedin post', st.session_state.post_content, image_path)
# st.success('Post has been successfully published on LinkedIn!')
# st.session_state.post_generated = False # Reset state after posting
# if __name__ == "__main__":
# main()
|