Created
February 20, 2025 09:03
-
-
Save Sohail-Khalid/bd7056ba108c851932ca6b68ea209369 to your computer and use it in GitHub Desktop.
langchain-ollama with streamlit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
from langchain.llms.ollama import Ollama | |
llm = Ollama(model='deepseek-r1:1.5b') | |
if "messages" not in st.session_state: | |
st.session_state.messages = [] | |
st.title('Deepseek with Streamlit') | |
st.write('Using LangChain, Ollama and streamlit. The ollama model is already installed locally on my machine') | |
for message in st.session_state.messages: | |
with st.chat_message(message['role']): | |
st.write(message['content']) | |
user_input = st.chat_input("Write something...") | |
if user_input and user_input.strip(): | |
st.session_state.messages.append({'role': 'user', 'content': user_input}) | |
with st.chat_message("user"): | |
st.markdown(user_input) | |
result = llm.predict(user_input) | |
st.session_state.messages.append({'role': 'deepseek','content':result}) | |
with st.chat_message("deepseek"): | |
st.markdown(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment