Gradio - Print response of bot with animated characters appearing one by one like chatGPT answers

I want the characters of the answer to appear gradually, not to receive the whole answer at once. I tried my code below and several variations but didn’t work

import gradio as gr

def user(user_message, history):
    return gradio.Interface.update_input(value="", interactive=False), history + [[user_message, None]]

def bot(history):
    bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
    history[-1][1] = ""  # Reset the bot's message
    for character in bot_message:
        history[-1][1] += character
        time.sleep(0.05)
        yield history
        time.sleep(0.2)  # Add a pause between characters

iface = gr.Interface(fn=user, inputs="text", outputs="text", css=css, interface_size=(100, 200))
iface.queue().launch()```

Seems I found a solution:

    index = GPTSimpleVectorIndex.load_from_disk('index.json')
    while True: 
        response = index.query(question, response_mode="compact")        
        messages.append({"User asks": question, "System response": response.response.strip()})
        #return response.response.strip()
        for el in range(1):
            history = []
            for el in response.response.strip():
                history.append(el)
                word = ''.join(history)
                time.sleep(0.02)
                yield str(word)
        break```