Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 4,645 Bytes
434f798 1f188d9 b0918e1 1f188d9 8dd1108 1f188d9 ad9d692 1f188d9 cbe51b9 1f188d9 cbe51b9 1f188d9 c6565e2 b7eca85 773ec73 78dea1a b7eca85 09d6ac2 773ec73 b80bf81 d3ba82c 78dea1a 773ec73 90c7959 a56363d 773ec73 3c830fa a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d 773ec73 a56363d c6565e2 d4ce55b c6565e2 db21dc3 b3ba3b3 |
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
import os
import re
import csv
import json
import time
import random
import asyncio
import discord
import logging
import os.path
import secrets
import gspread
import datetime
import requests
import threading
import gradio_client
import numpy as np
import pandas as pd
import gradio as gr
import plotly.graph_objects as go
from tabulate import tabulate
from requests import HTTPError
from gradio_client import Client
from discord import Color, Embed
from discord.ui import Button, View
from discord.ext import commands, tasks
from datetime import datetime, timedelta
from urllib.parse import urlparse, parse_qs
from apscheduler.executors.pool import ThreadPoolExecutor
from apscheduler.executors.asyncio import AsyncIOExecutor
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from gspread_formatting.dataframe import format_with_dataframe
from apscheduler.schedulers.background import BackgroundScheduler
from gspread_dataframe import get_as_dataframe, set_with_dataframe
from huggingface_hub import HfApi, list_liked_repos, list_metrics, list_models
DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)
global_df = pd.DataFrame()
test_merge = pd.read_csv("https://docs.google.com/spreadsheets/d/1C8aLqgCqLYcMiIFf-P_Aosaa03C_WLIB_UyqvjSdWg8/export?format=csv&gid=0")
@bot.event
async def on_ready():
global global_df
"""import data from google sheets -> HF Space df (doesn't make API call this way, as it's read-only)"""
global_df = test_merge
print(f"csv successfully retrieved: \n {global_df}")
@tasks.loop(minutes=1)
async def give_verified_roles():
try:
print("Starting the give_verified_roles task...")
# Access the global dataframe
global global_df
print(f"Dataframe loaded with {len(global_df)} rows.")
# Get the guild (server)
guild = bot.get_guild(879548962464493619)
print(f"Guild found: {guild}")
# Get the role
role = guild.get_role(900063512829755413)
print(f"Role found: {role}")
# Define the invite message
org_link = "https://huggingface.co/organizations/discord-community/share/wPKRAHYbAlaEaCxUxcqVyaaaeZcYagDvqc"
invite_message = "Click to join our community org on the HF Hub!"
print("Invite message and link prepared.")
# Cache members in the guild
print("Chunking guild members to cache...")
await guild.chunk()
print("Guild members chunked.")
# Iterate over the dataframe rows
for index, row in global_df.iterrows():
print(f"Processing row {index}: {row}")
# Extract Hugging Face username
hf_user_name = row['hf_user_name']
if pd.notna(hf_user_name) and hf_user_name.lower() != 'n/a':
print(f"Valid HF username found: {hf_user_name}")
# Extract and clean Discord ID
discord_id = row['discord_user_id'].strip('L')
print(f"Cleaned Discord ID: {discord_id}")
# Get the guild member
member = guild.get_member(int(discord_id))
if not member:
print(f"Member with Discord ID {discord_id} not found.")
continue
print(f"Member found: {member}")
# Check if the member already has the role
if role not in member.roles:
print(f"Adding role to member: {member}")
await member.add_roles(role)
print(f"Role added to member: {member}")
# Notify Lunar
lunar = bot.get_user(811235357663297546)
if lunar:
print(f"Notifying Lunar about verification for {member}")
await lunar.send(f"Verified role given to {member}!")
# Notify the member
print(f"Sending success message to {member}")
await member.send(
f"Verification successful! [{member} <---> {row['discord_user_name']}] \n🤗 {org_link} {invite_message}"
)
print("Finished processing all rows.")
except Exception as e:
print(f"Error encountered: {e}")
# runs discord bot in thread = helps avoid blocking calls
def run_bot():
bot.run(DISCORD_TOKEN)
threading.Thread(target=run_bot).start()
def greet(name):
return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch() |