Spaces:
Running
Running
import gradio as gr | |
import requests | |
import time | |
import pandas as pd | |
from datetime import datetime | |
DEFAULT_SYSTEM_PROMPT = """ | |
List of Tools: | |
- Sitespeed Checker - Check how fast monitored sites are in seconds. To use, just type ''run now'. | |
- Ads Checker - Shows the links of possible paid ads. To use, type the domain without 'https://www'. | |
""" | |
vLogDate = datetime.today().strftime('%Y/%m/%d') | |
websites = [ | |
"https://www.banyantree.com", | |
"https://www.angsana.com", | |
"https://www.cassia.com", | |
"https://www.dhawa.com", | |
"https://www.garrya.com", | |
"https://www.hommhotels.com", | |
"https://www.foliohotels.com", | |
"https://www.groupbanyan.com", | |
"https://veya.banyantree.com", | |
"https://escape.banyantree.com", | |
"https://essentials.banyantree.com", | |
"https://gifting.groupbanyan.com", | |
"https://www.raffles.com", | |
"https://www.aman.com", | |
"https://www.rosewoodhotels.com", | |
"https://www.fourseasons.com", | |
"https://www.radissonhotels.com", | |
"https://www.millenniumhotels.com", | |
"https://www.mandarinoriental.com", | |
"https://www.ritzcarlton.com", | |
"https://www.hyatt.com", | |
"https://www.ihg.com" | |
] | |
def generate_transparency_links(query,history): | |
""" | |
Generate links to transparency sites for a given query (e.g., brand name or website). | |
Args: | |
query (str): The brand name, website, or advertiser to search for. | |
Returns: | |
dict: A dictionary with transparency site names and their URLs. | |
""" | |
# Clean the query for URL encoding | |
import urllib.parse | |
encoded_query = query.strip() | |
# Base URLs for transparency sites | |
transparency_links = { | |
"Google Ads Transparency Center": f"https://adstransparency.google.com/?q={encoded_query}&domain={encoded_query}®ion=anywhere", | |
"Facebook Ads Library": f"https://www.facebook.com/ads/library/?active_status=all&ad_type=all&country=ALL&q={encoded_query}", | |
"TikTok Ads Library": f"https://library.tiktok.com/ads?region=all&adv_name={encoded_query}&adv_biz_ids=&query_type=1&sort_type=last_shown_date,desc", | |
"LinkedIn Ads Library": f"https://www.linkedin.com/ad-library/search?accountOwner={encoded_query}", | |
# Note: X doesn't have a public ads library, so we use a general search | |
"X Search for Promoted Content": f"https://x.com/search?q={encoded_query}%20promoted"} | |
return str(transparency_links) | |
def check_site_speed(url): | |
try: | |
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"} | |
start_time = time.time() | |
response = requests.get(url, headers=headers, timeout=10) | |
response.raise_for_status() | |
end_time = time.time() | |
return round(end_time - start_time, 3) # Response time in seconds | |
except requests.exceptions.RequestException as e: | |
print(f"Error checking {url}: {e}") | |
return None | |
def runchecks(message,history): | |
results = [] | |
results.append(['Website','Speed in Seconds']) | |
if message == 'run now' or message == 'Run Now': | |
for site in websites: | |
print(f"Checking site speed for {site}...") | |
speed = check_site_speed(site) | |
time.sleep(5) | |
if speed is not None: | |
print(f"Response time for {site}: {speed} seconds") | |
results.append([site,speed]) | |
df_log = pd.DataFrame(results) | |
return str(df_log) | |
else: | |
return(generate_transparency_links(message,history)) | |
Conversing = gr.ChatInterface(runchecks, chatbot=gr.Chatbot(height=600,label = "Output"), theme=gr.themes.Monochrome(), | |
title = 'BG ECommerce Utilities', description = DEFAULT_SYSTEM_PROMPT, css='footer {visibility: hidden}').launch() | |
#"Algorithm for this site is based on Readability Wiki - https://en.wikipedia.org/wiki/Readability " | |
if __name__ == "__main__": | |
Conversing.launch() |