File size: 2,215 Bytes
ef7bbea
 
 
 
 
34274a8
70aad33
34274a8
ef7bbea
 
 
 
 
34274a8
70aad33
34274a8
 
 
 
 
 
 
 
ef7bbea
 
34274a8
70aad33
dd2c1f0
34274a8
70aad33
 
 
 
 
 
 
 
34274a8
70aad33
 
 
 
 
34274a8
70aad33
 
34274a8
 
 
 
 
 
 
 
 
70aad33
 
34274a8
 
 
 
 
 
 
 
 
70aad33
 
34274a8
 
 
 
 
 
 
ef7bbea
 
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
72
73
74
75
76
77
import gradio as gr

contacts = []

def add_contact(name, phone, email):
    if not name:
        return contacts, " Please enter a name."

    contacts.append({
        "Name": name,
        "Phone": phone,
        "Email": email
    })

    return contacts, " Contact added successfully."

def search_contact(name):
    result = [c for c in contacts if name.lower() in c["Name"].lower()]
    return result

def delete_contact(name):
    global contacts
    contacts = [c for c in contacts if c["Name"].lower() != name.lower()]
    return contacts


# ---------- الثيم: هنا بنحدد شكل الألوان والحواف ----------
theme = gr.themes.Glass()

with gr.Blocks(title="Contact Management System", theme=theme) as demo:

    gr.Markdown(
        """
        # Contact Management System
        Manage your contacts easily using Python and Gradio.
        """
    )

    with gr.Tab("Add Contact"):
        with gr.Group():
            name = gr.Textbox(label="Name", placeholder="e.g. Ahmed Ali")
            phone = gr.Textbox(label="Phone", placeholder="e.g. 0790xxxxxxx")
            email = gr.Textbox(label="Email", placeholder="e.g. ahmed@example.com")

        add_btn = gr.Button("Add Contact", variant="primary")
        status = gr.Textbox(label="Status", interactive=False)
        table = gr.JSON(label="Contacts")

        add_btn.click(
            add_contact,
            inputs=[name, phone, email],
            outputs=[table, status]
        )

    with gr.Tab("Search Contact"):
        search_name = gr.Textbox(label="Search by Name", placeholder="Type a name...")
        search_btn = gr.Button("Search", variant="primary")
        search_result = gr.JSON(label="Result")

        search_btn.click(
            search_contact,
            inputs=search_name,
            outputs=search_result
        )

    with gr.Tab("Delete Contact"):
        delete_name = gr.Textbox(label="Name", placeholder="Exact name to delete")
        delete_btn = gr.Button("Delete", variant="stop")
        delete_table = gr.JSON(label="Contacts")

        delete_btn.click(
            delete_contact,
            inputs=delete_name,
            outputs=delete_table
        )

demo.launch()