HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/PraisonAI/docs/ui/streamlit/ollama-streamlit.mdx
---
title: "Ollama Streamlit UI"
description: "Create interactive chat interfaces with Ollama models using Streamlit"
icon: "window"
---

```mermaid
flowchart LR
    In[Input] --> UI[("Streamlit UI")]
    VDB[(Vector DB)] --> Agent
    Ollama[("Ollama")] --> Agent
    UI --> Agent[("Knowledge Agent")]
    Agent --> |Query| VDB
    Agent --> Out[Output]
    Out --> UI
    
    style In fill:#8B0000,color:#fff
    style UI fill:#FF4B4B,color:#fff,shape:circle
    style Ollama fill:#4169E1,color:#fff,shape:circle
    style Agent fill:#2E8B57,color:#fff,shape:circle
    style VDB fill:#4169E1,color:#fff,shape:cylinder
    style Out fill:#8B0000,color:#fff
```

## Prerequisites

<Steps>
    <Step title="Install Package">
        Install required packages:
        ```bash
        pip install "praisonaiagents[knowledge]" streamlit ollama
        ```

        <Note>
        streamlit for UI
        ollama for model hosting
        praisonaiagents[knowledge] for RAG capabilities
        </Note>
    </Step>

    <Step title="Setup Model">
        Pull Ollama models:
        ```bash
        # Large Language Model
        ollama pull deepseek-r1
        
        # Embedding Model
        ollama pull nomic-embed-text
        ```
    </Step>

    <Step title="Setup Environment">
        Configure environment:
        ```bash
        export OPENAI_BASE_URL=http://localhost:11434/v1
        export OPENAI_API_KEY=fake-key
        ```
    </Step>

    <Step title="Create File">
        Create a new file called `app.py` and add the following code:
    </Step>

    <Step title="Run Application">
        Start the Streamlit application:
        ```bash
        streamlit run app.py
        ```
    </Step>
</Steps>

## Code

```python
import streamlit as st
from praisonaiagents import Agent

def init_agent():
    config = {
        "vector_store": {
            "provider": "chroma",
            "config": {
                "collection_name": "praison",
                "path": ".praison"
            }
        },
        "llm": {
            "provider": "ollama",
            "config": {
                "model": "deepseek-r1:latest",
                "temperature": 0,
                "max_tokens": 8000,
                "ollama_base_url": "http://localhost:11434",
            },
        },
        "embedder": {
            "provider": "ollama",
            "config": {
                "model": "nomic-embed-text:latest",
                "ollama_base_url": "http://localhost:11434",
                "embedding_dims": 1536
            },
        },
    }
    
    return Agent(
        name="Knowledge Agent",
        instructions="You answer questions based on the provided knowledge.",
        knowledge=["kag-research-paper.pdf"],
        knowledge_config=config,
        user_id="user1",
        llm="deepseek-r1"
    )

st.title("Knowledge Agent Chat")

if "agent" not in st.session_state:
    st.session_state.agent = init_agent()
    st.session_state.messages = []

if "messages" in st.session_state:
    for message in st.session_state.messages:
        with st.chat_message(message["role"]):
            st.markdown(message["content"])

prompt = st.chat_input("Ask a question...")

if prompt:
    st.session_state.messages.append({"role": "user", "content": prompt})
    with st.chat_message("user"):
        st.markdown(prompt)

    with st.chat_message("assistant"):
        response = st.session_state.agent.start(prompt)
        st.markdown(response)
        st.session_state.messages.append({"role": "assistant", "content": response}) 
```

## Features

<CardGroup cols={2}>
  <Card title="Interactive Chat" icon="comments">
    Real-time chat interface with message history.
  </Card>
  <Card title="Knowledge Base" icon="database">
    RAG capabilities with ChromaDB integration.
  </Card>
  <Card title="Model Integration" icon="server">
    Uses Ollama for local model hosting.
  </Card>
  <Card title="Session Management" icon="clock-rotate-left">
    Maintains chat history in session state.
  </Card>
</CardGroup>

<Note>
  Make sure your system meets the requirements for running models locally through Ollama.
</Note>