File size: 5,117 Bytes
3dbdadf e2632b0 5b29985 75317a8 3dbdadf 570ffda 3dbdadf 75317a8 0c51e22 75317a8 0c51e22 75317a8 0c51e22 75317a8 570ffda 75317a8 570ffda 75317a8 3b51958 570ffda 7d45efb 75317a8 0c51e22 75317a8 |
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 |
#pip install --upgrade langchain_community
#pip install langchain_google_genai
import streamlit as st
from langchain_community.llms import OpenAI
#from langchain_community.llms import Gemini
#from langchain_google_gemini import Gemini
from langchain_google_genai import ChatGoogleGenerativeAI
def main():
st.title("Open AI or Gemini Options")
# Radio
st.header("Radio:")
radio = st.radio("Radio", ["Open AI", "Gemini", "TBD"]) # Removed extra space after "Gemini"
st.write("Selected option:", radio)
role = st.text_input("Enter Role")
st.write("Entered role:", role)
# Slider
st.header("Slider:")
temp = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.7, step=0.1) # Corrected slider label
st.write("Selected value:", temp)
# Topic
with st.form("my_form"):
topic = st.text_area("Enter the topic for your LinkedIn post:")
submitted = st.form_submit_button("Generate Post")
if submitted and topic:
# if radio == "Open AI": # Corrected if statement syntax and comparison
#generate_openai_post(role, temp)
post = generate_linkedin_post(topic, role,temp,radio)
st.info(post)
elif submitted and not topic:
st.error("Please enter a topic to generate a post.")
def generate_linkedin_post(topic, role,temp,radio):
# Enhanced prompt with additional context for better post generation
prompt = (
f"You as {role} Create a professional, engaging LinkedIn post about {topic}. "
f"Adjust the tone and style based on a temperature of {temp}. "
"It should start with an attention grabbing hook based on audience pain. "
"Then a line to agitate the user. This should be in the next line. "
"The post should be concise, informative, and suitable for a professional audience. "
"It should provide value, insights, or thought-provoking content related to the topic. "
"And only contain 3 points. "
)
if radio == "Open AI": # Corrected if statement syntax and comparison
# generate_openai_post(role, temp)
llm = OpenAI(temperature=temp, openai_api_key=st.secrets["OPENAI_API_KEY"]) # Corrected variable name
response = llm(prompt)
return response
elif radio == "Gemini":
#generate_gemini_post(role, temp)
llm = ChatGoogleGenerativeAI(model="gemini-pro")
result = llm.invoke(prompt)
return print(result.content)
""""
if radio == "Open AI": # Corrected if statement syntax and comparison
generate_openai_post(role, temp)
elif radio == "Gemini":
generate_gemini_post(role, temp)
def generate_openai_post(role, temp):
def generate_linkedin_post(topic, role):
# Enhanced prompt with additional context for better post generation
prompt = (
f"You as {role} Create a professional, engaging LinkedIn post about {topic}. "
f"Adjust the tone and style based on a temperature of {temp}. "
"It should start with an attention grabbing hook based on audience pain. "
"Then a line to agitate the user. This should be in the next line. "
"The post should be concise, informative, and suitable for a professional audience. "
"It should provide value, insights, or thought-provoking content related to the topic. "
"And only contain 3 points. "
)
llm = OpenAI(temperature=temp, openai_api_key=st.secrets["OPENAI_API_KEY"]) # Corrected variable name
response = llm(prompt)
return response
with st.form("my_form"):
topic = st.text_area("Enter the topic for your LinkedIn post:")
submitted = st.form_submit_button("Generate Post")
if submitted and topic:
post = generate_linkedin_post(topic, role)
st.info(post)
elif submitted and not topic:
st.error("Please enter a topic to generate a post.")
def generate_gemini_post(role, temp):
prompt = (
f"You as {role} Create a professional, engaging LinkedIn post about {topic}. "
f"Adjust the tone and style based on a temperature of {temp}. "
"It should start with an attention grabbing hook based on audience pain. "
"Then a line to agitate the user. This should be in the next line. "
"The post should be concise, informative, and suitable for a professional audience. "
"It should provide value, insights, or thought-provoking content related to the topic. "
"And only contain 3 points. "
)
llm = ChatGoogleGenerativeAI(model="gemini-pro")
result = llm.invoke(prompt)
return print(result.content)
# Call Gemini API functions to generate LinkedIn post
# gemini.generate_linkedin_post(topic, role)
st.error("Gemini API integration is not yet implemented.")
"""
if __name__ == "__main__":
main()
|