Integrations
Gradio
Trace Gradio chat UIs in Muster via the @observe decorator and capture user feedback as scores.
Gradio is a Python library for building web UIs around ML models. Combine it with Muster (langfuse) to trace every chat turn and capture user thumbs-up/down feedback as scores.
Setup
%pip install gradio langfuse openai httpximport os
os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..."
os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..."
os.environ["LANGFUSE_BASE_URL"] = "https://app.getmuster.io"
os.environ["OPENAI_API_KEY"] = "sk-..."
from langfuse import Langfuse
langfuse = Langfuse()Implementation
Use the @observe() decorator on the chat handler:
from langfuse import observe
from langfuse.openai import openai
@observe()
async def create_response(prompt: str, history):
response = openai.chat.completions.create(
messages=history,
model="gpt-4o-mini",
)
return responseCapture user feedback
Map Gradio thumbs-up/down events to Muster scores:
import gradio as gr
def handle_like(data: gr.LikeData):
langfuse.score(
value=1 if data.liked else 0,
name="user-feedback",
trace_id=current_trace_id,
)Wire handle_like to your Chatbot component's .like(...) event. The
score appears on the corresponding Muster trace and can be sliced in
analytics.