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)