Spaces:
Runtime error
Runtime error
import streamlit as st | |
from langchain_openai import ChatOpenAI | |
from langchain.schema import AIMessage, HumanMessage, SystemMessage | |
# Streamlit UI μ€μ | |
st.set_page_config(page_title="λ°μ΄ν°μ€νΈλ¦Όμ¦ μ± λͺ¨λΈ", page_icon=":robot:") | |
st.header("μλ νμΈμ. μ λ λ°μ΄ν°μ€νΈλ¦Όμ¦μμ μ μν κ³ νμ μ λ¬Έ μλ΄ AI λν λ΄μ΄μμ. μ λ λ§μνμλ κ²μ κΈ°μ΅νλ κ³μν΄μ μ§λ¬Έν΄μ£Όμλ©΄ λμ.") | |
# μΈμ λ©μμ§ μ΄κΈ°ν | |
if "sessionMessages" not in st.session_state: | |
st.session_state.sessionMessages = [ | |
SystemMessage(content="You are a renowned doctor specializing in hypertension.") | |
] | |
# λλ΅ λ‘λ ν¨μ | |
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") | |
return input_text | |
# ChatOpenAI κ°μ²΄ μμ± | |
chat = ChatOpenAI(temperature=0.7) | |
user_input = get_text() | |
submit = st.button('Generate') | |
if submit: | |
response = load_answer(user_input) | |
st.subheader("Answer:") | |
st.write(response, key=1) | |