Spaces:
Runtime error
Runtime error
import gradio as gr | |
with gr.Blocks() as demo: | |
chat_history = gr.State(value=[]) | |
def echo(message, history): | |
response = "You typed: " + message | |
chat_history.value.append( | |
{ | |
"user": message, | |
"bot": response, | |
} | |
) | |
return response | |
def generate_json(chat_history): | |
return chat_history.value | |
chatbox = gr.ChatInterface( | |
fn=echo, | |
title="Title Here", | |
description="Description for the task", | |
examples=["How can I help you?"], | |
submit_btn="Enter", | |
stop_btn="Stop generating", | |
retry_btn="Regenerate", | |
undo_btn="Undo last message", | |
clear_btn="Start a new conversation" | |
).queue() | |
chat_history_json = gr.JSON(generate_json(chat_history)) | |
gr.Markdown("### 📩 Generate the JSON file for your chat history!") | |
gr.Interface(fn=generate_json, | |
inputs=None, | |
outputs=[ chat_history_json ]) | |
demo.queue() | |
demo.launch() |