Create app3.py
Browse files
app3.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain_community.llms import OpenAI
|
| 3 |
+
from langchain_community.llms import Gemini
|
| 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"]) # Removed extra space after "Gemini"
|
| 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) # Corrected slider label
|
| 18 |
+
st.write("Selected value:", temp)
|
| 19 |
+
|
| 20 |
+
if radio == "Open AI": # Corrected if statement syntax and comparison
|
| 21 |
+
generate_openai_post(role, temp)
|
| 22 |
+
|
| 23 |
+
elif radio == "Gemini":
|
| 24 |
+
generate_gemini_post(role, temp)
|
| 25 |
+
|
| 26 |
+
def generate_openai_post(role, temp):
|
| 27 |
+
def generate_linkedin_post(topic, role):
|
| 28 |
+
# Enhanced prompt with additional context for better post generation
|
| 29 |
+
prompt = (
|
| 30 |
+
f"You as {role} Create a professional, engaging LinkedIn post about {topic}. "
|
| 31 |
+
"It should start with an attention grabbing hook based on audience pain. "
|
| 32 |
+
"Then a line to agitate the user. This should be in the next line. "
|
| 33 |
+
"The post should be concise, informative, and suitable for a professional audience. "
|
| 34 |
+
"It should provide value, insights, or thought-provoking content related to the topic. "
|
| 35 |
+
"And only contain 3 points. "
|
| 36 |
+
"The tone should be positive and encouraging, suitable for networking and professional growth."
|
| 37 |
+
)
|
| 38 |
+
llm = OpenAI(temperature=temp, openai_api_key=st.secrets["OPENAI_API_KEY"]) # Corrected variable name
|
| 39 |
+
response = llm(prompt)
|
| 40 |
+
return response
|
| 41 |
+
|
| 42 |
+
with st.form("my_form"):
|
| 43 |
+
topic = st.text_area("Enter the topic for your LinkedIn post:")
|
| 44 |
+
submitted = st.form_submit_button("Generate Post")
|
| 45 |
+
if submitted and topic:
|
| 46 |
+
post = generate_linkedin_post(topic, role)
|
| 47 |
+
st.info(post)
|
| 48 |
+
elif submitted and not topic:
|
| 49 |
+
st.error("Please enter a topic to generate a post.")
|
| 50 |
+
|
| 51 |
+
def generate_gemini_post(role, temp):
|
| 52 |
+
# Define a function to generate LinkedIn posts using the Gemini API
|
| 53 |
+
# Example implementation:
|
| 54 |
+
gemini = Gemini(api_key="YOUR_GEMINI_API_KEY", temperature=temp)
|
| 55 |
+
# Call Gemini API functions to generate LinkedIn post
|
| 56 |
+
# gemini.generate_linkedin_post(topic, role)
|
| 57 |
+
st.error("Gemini API integration is not yet implemented.")
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
main()
|