-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add first application post generator
- Loading branch information
andreabenevenuta
committed
Nov 23, 2023
1 parent
90f0cbc
commit 8f8bce0
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
openapi_key.txt | ||
openapi_key.txt | ||
|
||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import streamlit as st | ||
import langchain_helper as lch | ||
from dotenv import load_dotenv | ||
import os | ||
|
||
load_dotenv("openapi_key.txt") | ||
openai_api_key = os.getenv('OPENAI_API_KEY') | ||
|
||
st.title(":iphone: Dataroots Posts Generator") | ||
|
||
# Sidebar select box | ||
st.sidebar.title('Customize your post') | ||
social_network = st.sidebar.selectbox('Select Social Network:', ['Instagram', 'LinkedIn']) | ||
position = st.sidebar.selectbox('Select Position:', ['Machine Learning Engineer', 'Data Engineer', 'Data Strategy']) | ||
tone = st.sidebar.selectbox('Select Tone:', ['Formal', 'Informal']) | ||
max_words = st.sidebar.slider('Max Number of Words', min_value=100, max_value=1000, value=200) | ||
temperature = st.sidebar.slider('Model temperature', min_value=0.0, max_value=1.0, value=0.5, step=0.01) | ||
|
||
# Generate button | ||
if st.sidebar.button('Generate'): | ||
response = lch.generate_post_dataroots(social_network, position, tone, max_words, temperature, openai_api_key) | ||
st.text(response['generated_post']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import streamlit as st | ||
from langchain.llms import OpenAI | ||
from langchain.prompts import PromptTemplate | ||
from langchain.chains import LLMChain | ||
|
||
|
||
|
||
def generate_post_dataroots(social_network, position, tone, max_words, temperature, openai_api_key): | ||
llm = OpenAI(temperature=temperature, openai_api_key=openai_api_key) | ||
|
||
my_prompt = PromptTemplate( | ||
input_variables = ["social_network", "position", "tone", "max_words"], | ||
input_types={ | ||
"social_network": str, | ||
"position": str, | ||
"tone": str, | ||
"max_words": int | ||
}, | ||
template = """ | ||
You are Dataroots assistant and you are here to help HR create new posts on {social_network} to recruite new people. | ||
The post should be about looking for a {position}. | ||
The tone must be {tone}. | ||
The max number of words for the post should be {max_words}. | ||
Be as captivating as possible and use emojis to convey the message. | ||
""" | ||
) | ||
|
||
recruitment_chain = LLMChain(llm=llm, prompt=my_prompt, output_key="generated_post") | ||
|
||
response = recruitment_chain({ | ||
"social_network": social_network, | ||
"position": position, | ||
"tone": tone, | ||
"max_words": max_words | ||
}) | ||
|
||
return response | ||
|
||
if __name__ == "__main__": | ||
print(generate_post_dataroots("Instagram", "Machine Learning Engineer", "informal", 200, 0)) |