Spaces:
Sleeping
Sleeping
Download app.py from akshay33/ProjectCrysta: direct link, hf CLI and curl.
- Browser
- Download file 2.84 kB
-
https://huggingface.co/spaces/akshay33/ProjectCrysta/resolve/main/app.py
- Command line
-
hf download hf://spaces/akshay33/ProjectCrysta/app.py
-
curl -L -o app.py https://huggingface.co/spaces/akshay33/ProjectCrysta/resolve/main/app.py
2.84 kB
| import gradio as gr | |
| import pandas as pd | |
| import tempfile | |
| # Preloaded fallback data | |
| default_accounts = pd.read_csv("accounts.csv") | |
| default_contacts = pd.read_csv("contacts.csv") | |
| def extract_contacts(accounts_file, contacts_file, selected_status, selected_sites, contact_type): | |
| # Decide source: uploaded or default | |
| if accounts_file is not None and contacts_file is not None: | |
| final_accounts = pd.read_csv(accounts_file.name) | |
| final_contacts = pd.read_csv(contacts_file.name) | |
| else: | |
| final_accounts = default_accounts | |
| final_contacts = default_contacts | |
| # Filter accounts | |
| filtered_accounts = final_accounts[ | |
| (final_accounts['OVERALL_STATUS'].isin(selected_status)) & | |
| (final_accounts['SITE'].isin(selected_sites)) | |
| ] | |
| # Filter contacts | |
| filtered_contacts = final_contacts[ | |
| (final_contacts['STATUS'].str.upper() == contact_type.upper()) & | |
| (final_contacts['ACCOUNT_NAME'].isin(filtered_accounts['ACCOUNT_NAME'])) | |
| ] | |
| # Prepare output | |
| contacts = ", ".join(filtered_contacts['CONTACT'].dropna().astype(str)) | |
| emails = ", ".join(filtered_contacts['EMAIL'].dropna().astype(str)) | |
| sfids = ", ".join(filtered_contacts['SALESFORCE_EXTERNAL_ID'].dropna().astype(str)) | |
| df_out = pd.DataFrame({ | |
| 'CONTACTS': [contacts if contacts else f"No {contact_type} Contacts"], | |
| 'EMAILS': [emails if emails else f"No {contact_type} Emails"], | |
| 'SF_IDS': [sfids if sfids else f"No {contact_type} IDs"] | |
| }) | |
| # Save to temporary file for download | |
| tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".csv", mode='w', encoding='utf-8') | |
| df_out.to_csv(tmp_file, index=False) | |
| tmp_file.close() | |
| return df_out, tmp_file.name | |
| # Gradio UI | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## 🗂️ Contact Extractor - Optional Upload (Stealth Mode)") | |
| with gr.Row(): | |
| accounts_file = gr.File(label="Upload Accounts CSV (optional)", file_types=[".csv"]) | |
| contacts_file = gr.File(label="Upload Contacts CSV (optional)", file_types=[".csv"]) | |
| status_dropdown = gr.CheckboxGroup( | |
| choices=list(default_accounts['OVERALL_STATUS'].unique()), | |
| label="Select OVERALL_STATUS" | |
| ) | |
| site_dropdown = gr.CheckboxGroup( | |
| choices=list(default_accounts['SITE'].unique()), | |
| label="Select SITE" | |
| ) | |
| contact_type = gr.Radio(["Active", "Inactive"], label="Contact Type") | |
| submit_btn = gr.Button("Extract Contacts") | |
| output_table = gr.Dataframe(label="Filtered Contact Data") | |
| download_csv = gr.File(label="Download CSV") | |
| submit_btn.click( | |
| extract_contacts, | |
| inputs=[accounts_file, contacts_file, status_dropdown, site_dropdown, contact_type], | |
| outputs=[output_table, download_csv] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch(share=True) | |