VivekDS's picture
Update app4.py
5c12fb7 verified
import streamlit as st
from langchain_community.llms import OpenAI
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"])
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)
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:
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):
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":
llm = OpenAI(temperature=temp, openai_api_key=st.secrets["OPENAI_API_KEY"])
response = llm(prompt)
return response
elif radio == "Gemini":
llm = ChatGoogleGenerativeAI(model="gemini-pro",google_api_key =st.secrets["YOUR_GEMINI_API_KEY"])
result = llm.invoke(prompt)
return result.content
if __name__ == "__main__":
main()