File size: 1,073 Bytes
4200710
 
 
0369ce7
4200710
0369ce7
 
 
 
 
 
 
 
 
4200710
0369ce7
 
4200710
 
0369ce7
 
4200710
 
0369ce7
 
4200710
 
 
 
 
0369ce7
 
 
 
 
 
 
 
4200710
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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()