babelAI's picture
Update app.py
f03bf02 verified
import streamlit as st
from langchain_openai import ChatOpenAI
from langchain.schema import AIMessage, HumanMessage, SystemMessage
# Streamlit UI ์„ค์ •
st.set_page_config(page_title="๊ฒฝ๊ธฐ์ผ๋ณด ํ—ค๋“œ๋ผ์ธ ์ƒ์„ฑ AI", page_icon=":robot:")
#st.header("์•ˆ๋…•ํ•˜์„ธ์š”. ๊ธฐ์‚ฌ๋‚ด์šฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")
st.header("์•ˆ๋…•ํ•˜์„ธ์š”. ๊ธฐ์‚ฌ๋‚ด์šฉ์„ ์ž…๋ ฅํ•˜์‹œ๋ฉด ๋ฉ‹์ง„ ๊ธฐ์‚ฌ ์ œ๋ชฉ์„ ์ƒ์„ฑํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค!")
# ์„ธ์…˜ ๋ฉ”์‹œ์ง€ ์ดˆ๊ธฐํ™”
if "sessionMessages" not in st.session_state:
st.session_state.sessionMessages = [
SystemMessage(content="Imagine you are a seasoned journalist with a keen insight into societal trends, audience interests, and the pulse of current events. You have a knack for condensing complex stories into captivating titles that instantly grab attention. Your task is to create a newspaper article title that resonates with readers by sparking curiosity, offering value, or highlighting urgent issues. The title should be concise, no more than ten words, and must cleverly use language to intrigue, provoke thought, or convey the significance of the story. Consider using puns, alliterations, or unexpected juxtapositions to make the title memorable. Reflect on the core message of the article, its impact on the reader, and the broader implications for society. The title should stand as a call to action or an invitation to delve deeper into the narrative, compelling the subscriber to engage with the content immediately
Make a Korean title on the upper article.")
]
# ๋Œ€๋‹ต ๋กœ๋“œ ํ•จ์ˆ˜
def load_answer(question):
st.session_state.sessionMessages.append(HumanMessage(content=question))
assistant_answer = chat(st.session_state.sessionMessages)
st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content))
return assistant_answer.content
# ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๋ฐ›๊ธฐ
def get_text():
#input_text = st.text_input("๊ธฐ์ž: ", key="input")
input_text = st.text_input("Client: ", key="input")
return input_text
# ChatOpenAI ๊ฐ์ฒด ์ƒ์„ฑ
chat = ChatOpenAI(temperature=0.7)
user_input = get_text()
#submit = st.button('์ œ๋ชฉ ์ƒ์„ฑํ•˜๊ธฐ')
submit = st.button('Counsel')
if submit:
response = load_answer(user_input)
st.subheader("Answer:")
st.write(response, key=1)