VivekDS commited on
Commit
7549529
·
verified ·
1 Parent(s): 0c51e22

Create app4.py

Browse files
Files changed (1) hide show
  1. app4.py +51 -0
app4.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain_community.llms import OpenAI
3
+ from langchain_google_genai import ChatGoogleGenerativeAI
4
+
5
+ def main():
6
+ st.title("Open AI or Gemini Options")
7
+
8
+ # Radio
9
+ st.header("Radio:")
10
+ radio = st.radio("Radio", ["Open AI", "Gemini", "TBD"])
11
+ st.write("Selected option:", radio)
12
+ role = st.text_input("Enter Role")
13
+ st.write("Entered role:", role)
14
+
15
+ # Slider
16
+ st.header("Slider:")
17
+ temp = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.7, step=0.1)
18
+ st.write("Selected value:", temp)
19
+
20
+ # Topic
21
+ with st.form("my_form"):
22
+ topic = st.text_area("Enter the topic for your LinkedIn post:")
23
+ submitted = st.form_submit_button("Generate Post")
24
+ if submitted and topic:
25
+ post = generate_linkedin_post(topic, role, temp, radio)
26
+ st.info(post)
27
+ elif submitted and not topic:
28
+ st.error("Please enter a topic to generate a post.")
29
+
30
+ def generate_linkedin_post(topic, role, temp, radio):
31
+ prompt = (
32
+ f"You as {role} Create a professional, engaging LinkedIn post about {topic}. "
33
+ f"Adjust the tone and style based on a temperature of {temp}. "
34
+ "It should start with an attention grabbing hook based on audience pain. "
35
+ "Then a line to agitate the user. This should be in the next line. "
36
+ "The post should be concise, informative, and suitable for a professional audience. "
37
+ "It should provide value, insights, or thought-provoking content related to the topic. "
38
+ "And only contain 3 points."
39
+ )
40
+ if radio == "Open AI":
41
+ llm = OpenAI(temperature=temp, openai_api_key=st.secrets["OPENAI_API_KEY"])
42
+ response = llm(prompt)
43
+ return response
44
+
45
+ elif radio == "Gemini":
46
+ llm = ChatGoogleGenerativeAI(model="gemini-pro")
47
+ result = llm.invoke(prompt)
48
+ return result.content
49
+
50
+ if __name__ == "__main__":
51
+ main()