tapanpatro commited on
Commit
06ed50e
·
verified ·
1 Parent(s): e7ca957

Main app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import streamlit as st
4
+ import requests
5
+ import ollama
6
+
7
+ # Set up Streamlit Application
8
+ st.set_page_config(page_title="Streamlit UI with API Interaction", layout="centered")
9
+ st.title("Linkedin Post ")
10
+
11
+ # Example text for the left input box
12
+ example_text = "Work life balance"
13
+
14
+ # Initialize session state variables if not already done
15
+ if 'right_input' not in st.session_state:
16
+ st.session_state.right_input = ""
17
+ if 'image_prompt' not in st.session_state:
18
+ st.session_state.image_prompt = ""
19
+
20
+ # Function to update content based on input text
21
+ def update_content():
22
+ st.session_state.right_input = ''
23
+ st.session_state.image_prompt = ''
24
+
25
+ content = st.session_state.left_input
26
+ response_post = ollama.chat(model='linkedinpost', messages=[{'role': 'user', 'content': content}])
27
+ response_prompt = ollama.chat(model='llama2', messages=[{'role': 'user', 'content': f"write an image prompt to showcase this in 2 lines {content}"}])
28
+
29
+ st.session_state.right_input = response_post['message']['content']
30
+ st.session_state.image_prompt = response_prompt['message']['content']
31
+
32
+ update_content()
33
+
34
+ # Input text area
35
+ st.text_area("Topic to craft post", value=example_text, height=100, key='left_input', on_change=update_content)
36
+
37
+ # Display response and image prompt
38
+ st.markdown("##### Response")
39
+ st.write(st.session_state.right_input)
40
+ st.markdown("##### Image Prompt")
41
+ st.write(st.session_state.image_prompt)
42
+
43
+ # Create a button to manually trigger content update
44
+ if st.button("Generate Content"):
45
+ update_content()
46
+
47
+