Spaces:
Runtime error
Runtime error
Download app.py from nvymshr/rfp-tracker: direct link, hf CLI and curl.
- Browser
- Download file 4.41 kB
-
https://huggingface.co/spaces/nvymshr/rfp-tracker/resolve/main/app.py
- Command line
-
hf download hf://spaces/nvymshr/rfp-tracker/app.py
-
curl -L -o app.py https://huggingface.co/spaces/nvymshr/rfp-tracker/resolve/main/app.py
4.41 kB
| import gradio as gr | |
| import requests | |
| import pandas as pd | |
| from bs4 import BeautifulSoup | |
| # Define the sources to scrape RFPs from (Example: Placeholder URL) | |
| RFP_SOURCES = [ | |
| "https://www.example.com/rfp/environment", | |
| "https://www.example.com/rfp/sustainability", | |
| "https://www.example.com/rfp/health", | |
| "https://www.example.com/rfp/behaviour", | |
| "https://www.example.com/rfp/pollution" | |
| ] | |
| # Domains to filter RFPs by | |
| DOMAINS = ["Environment", "Sustainability", "Health", "Behaviour", "Pollution"] | |
| # Scraping function | |
| def scrape_rfps(domain): | |
| rfp_list = [] | |
| # Iterate through the sources | |
| for url in RFP_SOURCES: | |
| if domain.lower() not in url.lower(): | |
| continue # Skip irrelevant sources | |
| try: | |
| response = requests.get(url, timeout=10) | |
| response.raise_for_status() | |
| soup = BeautifulSoup(response.text, "lxml") | |
| # Example scraping logic: Adapt this to the actual RFP website structure | |
| rfp_items = soup.find_all("div", class_="rfp-item") | |
| for rfp in rfp_items: | |
| title = rfp.find("h2").text.strip() if rfp.find("h2") else "N/A" | |
| deadline = rfp.find("span", class_="deadline").text.strip() if rfp.find("span", class_="deadline") else "N/A" | |
| budget = rfp.find("span", class_="budget").text.strip() if rfp.find("span", class_="budget") else "N/A" | |
| geography = rfp.find("span", class_="geography").text.strip() if rfp.find("span", class_="geography") else "N/A" | |
| funder = rfp.find("span", class_="funder").text.strip() if rfp.find("span", class_="funder") else "N/A" | |
| partner = rfp.find("span", class_="partner").text.strip() if rfp.find("span", class_="partner") else "N/A" | |
| summary = rfp.find("p", class_="summary").text.strip() if rfp.find("p", class_="summary") else "N/A" | |
| rfp_list.append([title, deadline, budget, geography, funder, partner, summary]) | |
| except requests.exceptions.RequestException as e: | |
| print(f"Error scraping {url}: {str(e)}") | |
| continue | |
| # Convert to DataFrame | |
| columns = ["Title", "Deadline", "Budget", "Geography", "Funder", "Partner", "Summary"] | |
| return pd.DataFrame(rfp_list, columns=columns) if rfp_list else pd.DataFrame(columns=columns) | |
| # To-Do List for selected RFPs | |
| todo_list = [] | |
| # Function to add RFP to to-do list | |
| def add_to_todo_list(title, deadline, budget, geography, funder, partner, summary): | |
| todo_list.append([title, deadline, budget, geography, funder, partner, summary]) | |
| return f"Added '{title}' to your to-do list!" | |
| # Function to export the to-do list | |
| def export_todo_list(): | |
| if not todo_list: | |
| return "No items in your to-do list." | |
| df = pd.DataFrame(todo_list, columns=["Title", "Deadline", "Budget", "Geography", "Funder", "Partner", "Summary"]) | |
| file_path = "/mnt/data/todo_list.xlsx" | |
| df.to_excel(file_path, index=False) | |
| return file_path | |
| # Gradio Interface | |
| def display_rfps(domain): | |
| df = scrape_rfps(domain) | |
| return df | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## Automated RFP Tracking Tool") | |
| gr.Markdown("Select a domain to fetch RFPs.") | |
| domain_dropdown = gr.Dropdown(choices=DOMAINS, label="Select a Domain", value="Environment") | |
| rfps_output = gr.Dataframe() | |
| fetch_button = gr.Button("Fetch RFPs") | |
| fetch_button.click(display_rfps, inputs=domain_dropdown, outputs=rfps_output) | |
| gr.Markdown("### Add RFPs to To-Do List") | |
| title_input = gr.Textbox(label="Title") | |
| deadline_input = gr.Textbox(label="Deadline") | |
| budget_input = gr.Textbox(label="Budget") | |
| geography_input = gr.Textbox(label="Geography") | |
| funder_input = gr.Textbox(label="Funder") | |
| partner_input = gr.Textbox(label="Partner") | |
| summary_input = gr.Textbox(label="Summary") | |
| add_button = gr.Button("Add to To-Do List") | |
| add_status = gr.Textbox(label="Status") | |
| add_button.click(add_to_todo_list, inputs=[title_input, deadline_input, budget_input, geography_input, funder_input, partner_input, summary_input], outputs=add_status) | |
| gr.Markdown("### Export To-Do List as Excel") | |
| export_button = gr.Button("Export To-Do List") | |
| export_status = gr.File() | |
| export_button.click(export_todo_list, outputs=export_status) | |
| # Launching the app | |
| demo.launch(share=True, server_name="0.0.0.0") | |