Download app.py from dryudhis/LLMsChat: direct link, hf CLI and curl.
- Browser
- Download file 965 Bytes
-
https://huggingface.co/spaces/dryudhis/LLMsChat/resolve/main/app.py
- Command line
-
hf download hf://spaces/dryudhis/LLMsChat/app.py
-
curl -L -o app.py https://huggingface.co/spaces/dryudhis/LLMsChat/resolve/main/app.py
965 Bytes
| import streamlit as st | |
| from langchain.chat_models import ChatOpenAI | |
| from langchain.schema import ( | |
| AIMessage, | |
| HumanMessage, | |
| SystemMessage | |
| ) | |
| # UI | |
| st.set_page_config(page_title="Chat AI", page_icon=":robot:") | |
| st.header("Hi! Ask me anything!") | |
| if "sessionMessages" not in st.session_state : | |
| st.session_state.sessionMessages = [ | |
| SystemMessage(content="You are helpful assistant") | |
| ] | |
| 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("You:", key = input) | |
| return input_text | |
| chat = ChatOpenAI(temperature=0) | |
| user_input = get_text() | |
| submit = st.button("send") | |
| if submit: | |
| response = load_answer(user_input) | |
| st.subheader("answer") | |
| st.write(response, key=1) | |