Spaces:
Sleeping
Sleeping
Download app.py from fuerr18/Contact-Management-System: direct link, hf CLI and curl.
- Browser
- Download file 2.22 kB
-
https://huggingface.co/spaces/fuerr18/Contact-Management-System/resolve/refs%2Fpr%2F1/app.py
- Command line
-
hf download hf://spaces/fuerr18/Contact-Management-System@refs/pr/1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/fuerr18/Contact-Management-System/resolve/refs%2Fpr%2F1/app.py
2.22 kB
| 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.Default() | |
| 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() |