Skip to main content

A Streamlit component to visualize LLM reasoning processes with collapsible thought sections and rich markdown/LaTeX rendering

Project description

Streamlit Reasoning Visualizer

PyPI version License Streamlit

A beautiful, interactive Streamlit component for visualizing LLM reasoning processes with collapsible thought sections and rich markdown/LaTeX rendering.

Reasoning Visualizer Demo

✨ Features

  • 🧠 Collapsible Reasoning Section - Hide/show the model's chain-of-thought with smooth animations
  • 📝 Rich Markdown Rendering - Full markdown support including code blocks, tables, and formatting
  • 🔢 LaTeX Math Support - Beautiful equation rendering with KaTeX, including \boxed{} expressions
  • 🏷️ Multi-format Tag Parsing - Supports various reasoning tag formats used by different LLMs
  • 🎨 Modern UI - Clean, minimalist design with smooth animations using Framer Motion

📦 Installation

pip install streamlit-reasoning-visualizer

🚀 Quick Start

import streamlit as st
from reasoning_visualizer import visualizer

st.title("Reasoning Visualizer Demo")

# Sample response with reasoning tags
response = """<think>
Let me work through this step by step.
1. First, I need to understand the problem
2. Then, I'll apply the relevant formula
3. Finally, I'll calculate the result

Using the quadratic formula: $x = \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a}$
</think>

The answer is **42**.

$$\\boxed{x = 42}$$
"""

visualizer(text=response)

🏷️ Supported Reasoning Tag Formats

The component automatically detects and parses these tag formats:

Format Example
<think> <think>reasoning...</think>
[THOUGHT] [THOUGHT]reasoning...[/THOUGHT]
<reasoning> <reasoning>reasoning...</reasoning>
<chain_of_thought> <chain_of_thought>reasoning...</chain_of_thought>

If no tags are found, the entire text is displayed as the final answer.

📖 API Reference

visualizer(text, key=None)

Render the Reasoning Visualizer component.

Parameters:

Parameter Type Description
text str The raw text containing reasoning tags and the answer
key str, optional Unique key for multiple visualizer instances

Example with multiple visualizers:

visualizer(text=response1, key="viz1")
visualizer(text=response2, key="viz2")

🔧 Development

Prerequisites

  • Python 3.8+
  • Node.js 16+
  • npm

Setup

  1. Clone the repository:
git clone https://github.com/ketanmahandule/streamlit-reasoning-visualizer.git
cd streamlit-reasoning-visualizer
  1. Install Python dependencies:
pip install -e ".[dev]"
  1. Install frontend dependencies:
cd reasoning_visualizer/frontend
npm install
  1. Start development mode:

In reasoning_visualizer/__init__.py, set _RELEASE = False, then:

# Terminal 1: Start the React dev server
cd reasoning_visualizer/frontend
npm start

# Terminal 2: Run the example app
streamlit run example.py

Building the Frontend

cd reasoning_visualizer/frontend
npm run build

Running Tests

pytest tests/ -v

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

🙏 Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_reasoning_visualizer-0.1.0.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file streamlit_reasoning_visualizer-0.1.0.tar.gz.

File metadata

File hashes

Hashes for streamlit_reasoning_visualizer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bb3c5addcbcf340ed6e9b59403f8f7cf4e946bc47a23f024b714089dd3bd7c32
MD5 4d32cf33cf4358305b3eb8f2b6762ffe
BLAKE2b-256 9aee06a779aebcd06565533951a96aeb794817a2a41a23d484b347a0862b0387

See more details on using hashes here.

File details

Details for the file streamlit_reasoning_visualizer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_reasoning_visualizer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b2bff885892c8aa54fad39d41b311046cbf949bfb2c16e877365800c5fb3901
MD5 fd9ba7e6e9b70b6a5f700165b66212f7
BLAKE2b-256 b6a2084f906ab277c9f3c9f978bb9663c1a155c29d8aa40c96345ed15a80c713

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page