-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
67 lines (54 loc) · 2.13 KB
/
app.py
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
import openai
import streamlit as st
import langchain
from langchain_openai import OpenAI
from langchain.chains import LLMChain
from langchain_core.prompts import PromptTemplate
import os
# Enter your api key here in the api_key
api_key = ''
os.environ['OPENAI_API_KEY'] = api_key
def generate_LinkedIn_post(question):
template = ''' Question : {topic}
Answer : Generate a short Linkedin post of 250 words the {topic} with a strong hook. Do not number the lines. '''
prompt = PromptTemplate.from_template(template)
llm = OpenAI()
llm_chain = LLMChain(llm=llm, prompt=prompt)
answer = llm_chain.run(question)
return answer
def generate_tweet(question):
template = ''' Question : {topic}
Answer : Generate 200 word tweet for X on {topic}. Break the tweet into lines and use emjois and hashtags.
'''
llm_tweet = OpenAI()
prompt = PromptTemplate.from_template(template)
llm_chain2 = LLMChain(llm=llm_tweet, prompt=prompt)
answer = llm_chain2.run(question)
return answer
def generate_Facebook_post(question):
template = ''' Question : {topic}
Answer : Generate 300 word Facebook Style post on {topic}. Make the post semi formal and engaging. Use emoji and suggest some ideas for pictures.
'''
llm_tweet = OpenAI()
prompt = PromptTemplate.from_template(template)
llm_chain2 = LLMChain(llm=llm_tweet, prompt=prompt)
answer = llm_chain2.run(question)
return answer
with st.sidebar:
st.header('🦜🔗 Social Media Content Generator')
st.write('''
Made possible with:
\n- Langchain \n - Streamlit \n - OpenAI
''')
st.write('Developed by [Noor Aftab](www.linkedin.com/in/nooraftab)')
st.title('Social Media Content Bot ☕')
topic = st.text_input('What topic do you want to post about?')
if st.button('Generate LinkedIn Posts'):
response = generate_LinkedIn_post(topic)
st.write(response)
if st.button('Generate Tweet'):
response = generate_tweet(topic)
st.write(response)
if st.button('Generate Facebook Post'):
response = generate_Facebook_post(topic)
st.write(response)