The gr.LikeData class is a subclass of gr.EventData that specifically carries information about the .like() event. When gr.LikeData is added as a type hint to an argument of an event listener method, a gr.LikeData object will automatically be passed as the value of that argument. The attributes of this object contains information about the event that triggered the listener.
Example Usage
import gradio as gr
deftest(value, like_data: gr.LikeData):return{"chatbot_value": value,"liked_message": like_data.value,"liked_index": like_data.index,"liked_or_disliked_as_bool": like_data.liked
}with gr.Blocks()as demo:
c = gr.Chatbot([("abc","def")])
t = gr.JSON()
c.like(test, c, t)
demo.launch()
Attributes
Parameter
Description
index
int | tuple[int, int]
The index of the liked/disliked item. Is a tuple if the component is two dimensional.