gradio icon indicating copy to clipboard operation
gradio copied to clipboard

gr.Chatbot cannot use gr.Markdown / gr.DataFrame while showing the results

Open sglbl opened this issue 8 months ago • 4 comments

  • [y] I have searched to see if a similar issue already exists.

Is your feature request related to a problem? Please describe.
I want to use gr.DataFrame in output of chatbot.

Describe the solution you'd like
Show the result of gr.DataFrame as a table inside chatbot result.

Additional context
gradio.__version__: '4.37.1' Code:

import gradio as gr
import time

def html_works():
   history = []
   history.append(["",None])
   text_to_show_in_chatbot = '**testing** normal md <br> <table border="1" style="width:100%"><tr><th>Label</th><th>Value</th></tr><tr><th>x</th><th>y</th></tr>'
   response = [(text_to_show_in_chatbot, None)]

   for letter in response[0][0]:
      history[-1][0] += letter
      time.sleep(0.01)
      yield history
   
   return response

def dataframe_does_not_work():
   history = []
   history.append(["",None])
   df_to_show_in_chatbot = gr.DataFrame( # gr.Markdown neither work
                              headers=["name", "age", "gender"],
                              datatype=["str", "number", "str"],
                              col_count=(3, "fixed"),
                              type='array' 
                              ## returning as an array / list of lists also okay, I can convert it to normal markdown but I also don't get any output as a list
                           )
   print(f'{type(df_to_show_in_chatbot) = }')
   response = [(df_to_show_in_chatbot, None)]
   
   for letter in response[0][0]:
      history[-1][0] += letter
      time.sleep(0.01)
      yield history
   
   return response

with gr.Blocks() as demo:
   button = gr.Button()
   chatbot = gr.Chatbot(render_markdown=True)
   # button.click(html_works, outputs = chatbot)   
   button.click(dataframe_does_not_work, outputs = chatbot)   
   
demo.queue(default_concurrency_limit=None)
demo.launch()

sglbl avatar Jun 28 '24 14:06 sglbl