Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,730 Bytes
d8bbcde |
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 |
import gradio as gr
class CRUDApp:
def __init__(self):
self.data = []
def create(self, name, age):
self.data.append({"name": name, "age": age})
return self.data
def read(self):
return self.data
def update(self, index, name, age):
if index < len(self.data):
self.data[index] = {"name": name, "age": age}
return self.data
def delete(self, index):
if index < len(self.data):
del self.data[index]
return self.data
with gr.Blocks() as gradio_interface:
gr.Markdown("CRUD Application")
with gr.Row():
with gr.Column():
name_input = gr.Textbox(label="Name")
age_input = gr.Number(label="Age")
create_button = gr.Button("Create")
with gr.Column():
read_button = gr.Button("Read")
update_button = gr.Button("Update")
delete_button = gr.Button("Delete")
output = gr.Dataframe(label="Data")
crud_app = CRUDApp()
def create_event(name, age):
return crud_app.create(name, age)
def read_event():
return crud_app.read()
def update_event(index, name, age):
return crud_app.update(index, name, age)
def delete_event(index):
return crud_app.delete(index)
create_button.click(fn=create_event, inputs=[name_input, age_input], outputs=[output])
read_button.click(fn=read_event, outputs=[output])
update_button.click(fn=update_event, inputs=[gr.Number(label="Index"), name_input, age_input], outputs=[output])
delete_button.click(fn=delete_event, inputs=[gr.Number(label="Index")], outputs=[output])
#gr.Interface(gradio_interface, "gradio_interface").launch() |