Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -28,6 +28,11 @@ def update_author_by_title(title, new_author):
|
|
28 |
|
29 |
return f"Updated author for the book '{title}' from '{existing_author}' to '{new_author}'."
|
30 |
|
|
|
|
|
|
|
|
|
|
|
31 |
def process_data(option, title, author):
|
32 |
if option == "Insert":
|
33 |
return add_book(title, author)
|
@@ -41,13 +46,18 @@ def process_data(option, title, author):
|
|
41 |
return update_author_by_title(title, author)
|
42 |
else:
|
43 |
return "Title and author are required for update."
|
|
|
|
|
|
|
|
|
|
|
44 |
else:
|
45 |
return "Invalid option"
|
46 |
|
47 |
demo = gr.Interface(
|
48 |
fn=process_data,
|
49 |
inputs=[
|
50 |
-
gr.Radio(["Insert", "Fetch", "Update"], label="Select Operation"),
|
51 |
gr.Textbox(label="Title"),
|
52 |
gr.Textbox(label="Author"),
|
53 |
],
|
|
|
28 |
|
29 |
return f"Updated author for the book '{title}' from '{existing_author}' to '{new_author}'."
|
30 |
|
31 |
+
def delete_book_by_title(title):
|
32 |
+
# Remove the book with the specified title from the table
|
33 |
+
table.remove(tinydb.where("title") == title)
|
34 |
+
return f"Deleted book with title '{title}' from the database."
|
35 |
+
|
36 |
def process_data(option, title, author):
|
37 |
if option == "Insert":
|
38 |
return add_book(title, author)
|
|
|
46 |
return update_author_by_title(title, author)
|
47 |
else:
|
48 |
return "Title and author are required for update."
|
49 |
+
elif option == "Delete":
|
50 |
+
if title:
|
51 |
+
return delete_book_by_title(title)
|
52 |
+
else:
|
53 |
+
return "Title is required for delete."
|
54 |
else:
|
55 |
return "Invalid option"
|
56 |
|
57 |
demo = gr.Interface(
|
58 |
fn=process_data,
|
59 |
inputs=[
|
60 |
+
gr.Radio(["Insert", "Fetch", "Update", "Delete"], label="Select Operation"),
|
61 |
gr.Textbox(label="Title"),
|
62 |
gr.Textbox(label="Author"),
|
63 |
],
|