Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,118 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import re
|
| 3 |
-
import openai
|
| 4 |
-
from paraphrase_post import get_original_url , paraphrased_post
|
| 5 |
-
from advance_post import google_search , advanced_post
|
| 6 |
-
from langchain.chat_models import ChatOpenAI
|
| 7 |
-
from langchain_groq import ChatGroq
|
| 8 |
-
# from langchain.llms import HuggingFaceHub
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def main():
|
| 13 |
-
st.title("LinkedIn Post Creator")
|
| 14 |
-
|
| 15 |
-
# Initialize SessionState dictionary
|
| 16 |
-
session_state = st.session_state
|
| 17 |
-
|
| 18 |
-
if 'paraphrase' not in session_state:
|
| 19 |
-
session_state.paraphrase = ""
|
| 20 |
-
if 'keywords' not in session_state:
|
| 21 |
-
session_state.keywords = ""
|
| 22 |
-
if 'take_aways' not in session_state:
|
| 23 |
-
session_state.take_aways = ""
|
| 24 |
-
if 'highlights' not in session_state:
|
| 25 |
-
session_state.highlights = ""
|
| 26 |
-
|
| 27 |
-
if 'advancepost' not in session_state:
|
| 28 |
-
session_state.advancepost = ""
|
| 29 |
-
|
| 30 |
-
url = st.sidebar.text_input("Enter URL:", placeholder="Enter URL here...")
|
| 31 |
-
option = st.sidebar.selectbox('Select Model:', ('GPT-4',))
|
| 32 |
-
temperature= st.sidebar.select_slider(
|
| 33 |
-
'How much accurate post you want ?',
|
| 34 |
-
options=['Less accuracy', 9, 8, 7, 6, 5,4,3 ,2,1,'High accuracy'])
|
| 35 |
-
if temperature=='Less accuracy':
|
| 36 |
-
temperature=10
|
| 37 |
-
elif temperature=="High accuracy":
|
| 38 |
-
temperature=0
|
| 39 |
-
temperature=temperature/10
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
if option=="GPT-4":
|
| 43 |
-
api_key=st.sidebar.text_input("API Key:",placeholder="Enter OpenAI API Key...")
|
| 44 |
-
if api_key:
|
| 45 |
-
model=ChatOpenAI(model="gpt-4-turbo-preview" , temperature=temperature , api_key=api_key)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
if st.sidebar.button("Submit"):
|
| 49 |
-
if url:
|
| 50 |
-
if api_key:
|
| 51 |
-
original_url = get_original_url(url)
|
| 52 |
-
match = re.match(r"https?://(?:www\.)?linkedin\.com/(posts|feed|pulse)/.*", original_url) # checking domain and url page (means it should only be a post nothing else like login page or something else)
|
| 53 |
-
|
| 54 |
-
if match:
|
| 55 |
-
try:
|
| 56 |
-
session_state.paraphrase, session_state.keywords, session_state.take_aways, session_state.highlights = paraphrased_post(url , model)
|
| 57 |
-
except (openai.AuthenticationError) as e:
|
| 58 |
-
st.sidebar.error("Enter your valid API key")
|
| 59 |
-
else:
|
| 60 |
-
st.sidebar.error("Put a valid LinkedIn post url only")
|
| 61 |
-
else:
|
| 62 |
-
st.sidebar.error("Please enter API Key")
|
| 63 |
-
else:
|
| 64 |
-
st.sidebar.error("Please enter url")
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
paraphrase_text=st.text_area("Generated LinkedIn post",value=session_state.paraphrase, height=400)
|
| 69 |
-
# import pyperclip
|
| 70 |
-
# if st.button('Copy'):
|
| 71 |
-
# pyperclip.copy(paraphrase_text)
|
| 72 |
-
# st.success('Text copied successfully!')
|
| 73 |
-
|
| 74 |
-
if st.sidebar.toggle("Show Details") and session_state.keywords:
|
| 75 |
-
st.write("Keywords:")
|
| 76 |
-
for i, statement in enumerate(session_state.keywords, start=1):
|
| 77 |
-
st.write(f"{i}. {statement}")
|
| 78 |
-
|
| 79 |
-
st.write("Take Aways:")
|
| 80 |
-
for i, statement in enumerate(session_state.take_aways, start=1):
|
| 81 |
-
st.write(f"{i}. {statement}")
|
| 82 |
-
|
| 83 |
-
st.write("Highlights:")
|
| 84 |
-
for i, statement in enumerate(session_state.highlights, start=1):
|
| 85 |
-
st.write(f"{i}. {statement}")
|
| 86 |
-
|
| 87 |
-
#------------------------------------------------------------Advance LinkedIn post code below-----------------------------------------------------------------
|
| 88 |
-
|
| 89 |
-
if st.sidebar.toggle("Advance LinkedIn Post"):
|
| 90 |
-
google_api_key=st.sidebar.text_input("Google API Key:",placeholder="Enter Google Search API Key...")
|
| 91 |
-
search_engine_id=st.sidebar.text_input("Search Engine ID:",placeholder="Enter Search Engine ID...")
|
| 92 |
-
google_api_key = "AIzaSyDh-lkJh2Zef0t6UVqSu_w3njpucx40mDc"
|
| 93 |
-
search_engine_id = "44bbd32a2b2fc4418"
|
| 94 |
-
if st.sidebar.button("Generate Advance Post"):
|
| 95 |
-
if google_api_key:
|
| 96 |
-
if search_engine_id:
|
| 97 |
-
all_links =google_search(session_state.paraphrase ,model , google_api_key,search_engine_id)
|
| 98 |
-
session_state.advancepost , docs=advanced_post(all_links ,model ,session_state.paraphrase)
|
| 99 |
-
if len(docs)==0:
|
| 100 |
-
st.sidebar.error("Please Check your both credentials carefully")
|
| 101 |
-
|
| 102 |
-
else:
|
| 103 |
-
st.sidebar.error("Please enter Search Engine ID")
|
| 104 |
-
else:
|
| 105 |
-
st.sidebar.error("Please enter Google API Key")
|
| 106 |
-
advance_post=st.text_area("Advance LinkedIn post",value=session_state.advancepost, height=400)
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
# if st.button('Copy Advanced Post'):
|
| 110 |
-
# pyperclip.copy(advance_post)
|
| 111 |
-
# st.success('Text copied successfully!')
|
| 112 |
-
#--------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 113 |
-
|
| 114 |
-
if __name__ == "__main__":
|
| 115 |
-
main()
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|