Skip to content

Instantly share code, notes, and snippets.

@Sohail-Khalid
Created February 20, 2025 09:03
Show Gist options
  • Save Sohail-Khalid/bd7056ba108c851932ca6b68ea209369 to your computer and use it in GitHub Desktop.
Save Sohail-Khalid/bd7056ba108c851932ca6b68ea209369 to your computer and use it in GitHub Desktop.
langchain-ollama with streamlit
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