linkedin / app.py
tapanpatro's picture
Main app.py
06ed50e verified
# app.py
import streamlit as st
import requests
import ollama
# Set up Streamlit Application
st.set_page_config(page_title="Streamlit UI with API Interaction", layout="centered")
st.title("Linkedin Post ")
# Example text for the left input box
example_text = "Work life balance"
# Initialize session state variables if not already done
if 'right_input' not in st.session_state:
st.session_state.right_input = ""
if 'image_prompt' not in st.session_state:
st.session_state.image_prompt = ""
# Function to update content based on input text
def update_content():
st.session_state.right_input = ''
st.session_state.image_prompt = ''
content = st.session_state.left_input
response_post = ollama.chat(model='linkedinpost', messages=[{'role': 'user', 'content': content}])
response_prompt = ollama.chat(model='llama2', messages=[{'role': 'user', 'content': f"write an image prompt to showcase this in 2 lines {content}"}])
st.session_state.right_input = response_post['message']['content']
st.session_state.image_prompt = response_prompt['message']['content']
update_content()
# Input text area
st.text_area("Topic to craft post", value=example_text, height=100, key='left_input', on_change=update_content)
# Display response and image prompt
st.markdown("##### Response")
st.write(st.session_state.right_input)
st.markdown("##### Image Prompt")
st.write(st.session_state.image_prompt)
# Create a button to manually trigger content update
if st.button("Generate Content"):
update_content()