Gradio integration #4586
-
|
Thank you so much for the amazing tool! I've been using callback handler in python with gradio but struggling to get the user feedback recorded with the trace. Here's the example with langchain agent and gradio - https://www.gradio.app/main/guides/agents-and-tool-usage#a-real-example-using-langchain-agents Here's the like/dislike event documentation with gradio - https://www.gradio.app/main/guides/chatbot-specific-events#the-like-event I was able to record the whole conversation as a trace but I'd like to record every call as a trace (as does the callback handler) along with user feedback using Any help is appreciated! Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
|
To record user feedback using the
Here's a basic example of how you might implement this in Python: from langfuse import Langfuse
from langfuse.callback import CallbackHandler
import gradio as gr
# Initialize Langfuse and CallbackHandler
langfuse = Langfuse()
langfuse_handler = CallbackHandler(
secret_key="sk-lf-...",
public_key="pk-lf-...",
host="https://cloud.langfuse.com"
)
# Your Langchain code with the callback handler
# chain.invoke({"input": "<user_input>"}, config={"callbacks": [langfuse_handler]})
# Function to handle like event
def handle_like(trace_id, feedback_value):
langfuse.score(
trace_id=trace_id,
name="user-feedback",
value=feedback_value,
comment="User feedback recorded"
)
# Gradio interface setup
def gradio_interface(input_text):
# Your processing logic
return "Processed output"
iface = gr.Interface(
fn=gradio_interface,
inputs="text",
outputs="text"
)
# Attach the like event handler
iface.like(fn=lambda trace_id: handle_like(trace_id, 1))
iface.launch()In this setup, replace |
Beta Was this translation helpful? Give feedback.
-
|
Amazing that the bot could answer my specific question! I love this tool even more!! |
Beta Was this translation helpful? Give feedback.
-
|
New reference notebook for gradio here: https://langfuse.com/docs/integrations/other/gradio |
Beta Was this translation helpful? Give feedback.
New reference notebook for gradio here: https://langfuse.com/docs/integrations/other/gradio