Build a DeepSeek chatbot using Streamlit and Ciyuano

Β·2 min readΒ·206 views
Build a DeepSeek chatbot using Streamlit and Ciyuano

Goal

Build a complete web chat interface in 30 minutes, supporting streaming output, conversation history, and model switching.


Tech Stack

  • Frontend: Streamlit (pure Python, no HTML/JS needed)
  • Backend: Ciyuano API (DeepSeek V4)
  • Language: Python 3.10+

Step 1: Install Dependencies

pip install streamlit openai

Step 2: Create app.py

import streamlit as st
from openai import OpenAI

st.set_page_config(page_title="DeepSeek Chat", page_icon="πŸ€–")
st.title("πŸ€– DeepSeek chat assistant")

with st.sidebar:
    st.header("βš™οΈ Settings")
    api_key = st.text_input("API Key", type="password")
    model = st.selectbox("model", ["deepseek-v4", "glm-5", "qwen-plus", "auto"])
    st.caption("Powered by Ciyuano")

if "messages" not in st.session_state:
    st.session_state.messages = []

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

if prompt := st.chat_input("Enter your question..."):
    if not api_key:
        st.error("Please enter first API Key")
        st.stop()

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

    client = OpenAI(
        base_url="https://www.ciyuano.com/v1",
        api_key=api_key
    )

    with st.chat_message("assistant"):
        message_placeholder = st.empty()
        full_response = ""
        stream = client.chat.completions.create(
            model=model,
            messages=st.session_state.messages,
            stream=True
        )
        for chunk in stream:
            if chunk.choices[0].delta.content:
                full_response += chunk.choices[0].delta.content
                message_placeholder.markdown(full_response + "β–Œ")
        message_placeholder.markdown(full_response)

    st.session_state.messages.append(
        {"role": "assistant", "content": full_response}
    )

Step 3: Run

streamlit run app.py

The browser automatically opens http://localhost:8501, and a complete chat interface appears!

Preview

  • βœ… Streaming word-by-word output (typewriter effect)
  • βœ… Multi-turn conversation memory
  • βœ… Real-time model switching
  • βœ… Pure Python implementation, zero frontend code

Deployment

nohup streamlit run app.py --server.port 8501 &

Configure Nginx reverse proxy + SSL to serve externally.


Summary

The Streamlit + Ciyuano combination lets you have a production-ready AI chat application in 30 minutes. No complex frontend frameworks, no server-side API development, all done with Python.

Comments are not yet available, stay tuned