Spaces:
Runtime error
Runtime error
File size: 1,475 Bytes
60aa6e7 8b6e3d9 60aa6e7 8b6e3d9 60aa6e7 8b6e3d9 60aa6e7 8b6e3d9 60aa6e7 8b6e3d9 |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import gradio as gr
import random
class Human:
def __init__(self):
self.count = 0
print("init")
def reset(self):
self.count = 0
print("reset")
def echo(self, message, history):
self.count += 1
return "this round:"+str(self.count)
#h = Human()
#hs = gr.State(h)
def output(message, history, s):
r = s.echo(message, history)
return r
'''
demo = gr.ChatInterface(
fn=output,
additional_inputs=[hs],
retry_btn=None,
undo_btn=None,
submit_btn="ει",
#clear_btn="εζ₯δΈε±",
clear_btn=gr.ClearButton(hs),
title="Echo Bot")
'''
def respond(message, history, state):
bot_message = state.echo(message, history)
history.append((message, bot_message))
return "", history, state
def cl(message, history, state):
message = ""
history.clear()
state.reset()
return "", history, state
with gr.Blocks() as demo:
label = gr.Label("hello world")
html = gr.HTML("<h1>Greeting App</h1> \
<p>This app greets people.</p>")
chatbot = gr.Chatbot(label="heoo world", value=[('ff','bb'),('cc','dd')])
msg = gr.Textbox()
submit = gr.Button("ει" )
clear = gr.ClearButton()
h = Human()
state = gr.State(h)
clear.click(cl, [msg, chatbot, state], [msg, chatbot, state])
submit.click(respond, [msg, chatbot, state], [msg, chatbot, state])
demo.launch()
|