Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
can readd periodic_api_test for hub stuff tomorrow
Browse files
app.py
CHANGED
@@ -47,7 +47,6 @@ with open(file_path, 'w') as json_file:
|
|
47 |
json.dump(service_account, json_file)
|
48 |
gspread_bot = gspread.service_account(filename='service_account.json')
|
49 |
worksheet = gspread_bot.open("levelbot").sheet1
|
50 |
-
worksheet2 = gspread_bot.open("hf_discord_verified_users_test").sheet1
|
51 |
test_merge_worksheet = gspread_bot.open("test_merge").sheet1
|
52 |
""""""
|
53 |
bot_ids = [1136614989411655780, 1166392942387265536, 1158038249835610123, 1130774761031610388, 1155489509518098565, 1155169841276260546, 1152238037355474964, 1154395078735953930]
|
@@ -56,7 +55,6 @@ api = HfApi()
|
|
56 |
""""""
|
57 |
#csv_file = 'data.csv'
|
58 |
global_df = pd.DataFrame()
|
59 |
-
worksheet2_df = pd.DataFrame()
|
60 |
print(type(global_df))
|
61 |
community_global_df = pd.DataFrame()
|
62 |
community_global_df_with_id = pd.DataFrame()
|
@@ -69,7 +67,6 @@ data2 = pd.read_csv("https://docs.google.com/spreadsheets/d/1T_twNONDSZ8zw7aDcYh
|
|
69 |
async def on_ready():
|
70 |
try:
|
71 |
global global_df
|
72 |
-
global worksheet2_df
|
73 |
await asyncio.sleep(1.1)
|
74 |
print(f'Logged in as {bot.user.name}')
|
75 |
print(f"XP_PER_MESSAGE: {XP_PER_MESSAGE}")
|
@@ -78,11 +75,6 @@ async def on_ready():
|
|
78 |
global_df = test_merge
|
79 |
print(f"csv successfully retrieved: \n {global_df}")
|
80 |
|
81 |
-
worksheet2_df = data2.copy()
|
82 |
-
worksheet2_df['discord_user_id'] = worksheet2_df['discord_user_id'].astype(str)
|
83 |
-
worksheet2_df['id_recover_test'] = worksheet2_df['id_recover_test'].astype(str)
|
84 |
-
print(worksheet2_df.dtypes)
|
85 |
-
|
86 |
# updates both leaderboards
|
87 |
#await remove_huggingfolks() # to initialize
|
88 |
#print(community_global_df_with_id)
|
@@ -120,45 +112,6 @@ def calculate_level(xp):
|
|
120 |
def calculate_xp(level):
|
121 |
return (int(level ** 3))
|
122 |
|
123 |
-
|
124 |
-
processed_users = set()
|
125 |
-
|
126 |
-
async def periodic_api_test(): # needs rewrite, can do same thing and interact with csv -> push to google sheets
|
127 |
-
try:
|
128 |
-
# this should be gspread type function (do not mix with discord at all
|
129 |
-
global worksheet2_df
|
130 |
-
# get
|
131 |
-
for index, user in enumerate(worksheet2_df['hf_user_name']):
|
132 |
-
if user in processed_users:
|
133 |
-
continue
|
134 |
-
await asyncio.sleep(0.5)
|
135 |
-
url = f"https://huggingface.co/api/users/{user}/overview"
|
136 |
-
response = requests.get(url)
|
137 |
-
|
138 |
-
if response.status_code == 200:
|
139 |
-
data = response.json()
|
140 |
-
|
141 |
-
likes = data["numLikes"]
|
142 |
-
models = data["numModels"]
|
143 |
-
datasets = data["numDatasets"]
|
144 |
-
spaces = data["numSpaces"]
|
145 |
-
discussions = data["numDiscussions"]
|
146 |
-
papers = data["numPapers"]
|
147 |
-
upvotes = data["numUpvotes"]
|
148 |
-
|
149 |
-
worksheet2_df.loc[index:index, 'likes':'upvotes'] = [[likes, models, datasets, spaces, discussions, papers, upvotes]]
|
150 |
-
pd.set_option('display.max_rows', 30)
|
151 |
-
print(worksheet2_df)
|
152 |
-
|
153 |
-
|
154 |
-
processed_users.add(user)
|
155 |
-
print(processed_users)
|
156 |
-
else:
|
157 |
-
print(f"Failed to retrieve data for user {user}. Status code: {response.status_code}")
|
158 |
-
|
159 |
-
except Exception as e:
|
160 |
-
print(f"periodic_api_test Error: {e}")
|
161 |
-
|
162 |
|
163 |
async def add_exp(member_id):
|
164 |
try:
|
|
|
47 |
json.dump(service_account, json_file)
|
48 |
gspread_bot = gspread.service_account(filename='service_account.json')
|
49 |
worksheet = gspread_bot.open("levelbot").sheet1
|
|
|
50 |
test_merge_worksheet = gspread_bot.open("test_merge").sheet1
|
51 |
""""""
|
52 |
bot_ids = [1136614989411655780, 1166392942387265536, 1158038249835610123, 1130774761031610388, 1155489509518098565, 1155169841276260546, 1152238037355474964, 1154395078735953930]
|
|
|
55 |
""""""
|
56 |
#csv_file = 'data.csv'
|
57 |
global_df = pd.DataFrame()
|
|
|
58 |
print(type(global_df))
|
59 |
community_global_df = pd.DataFrame()
|
60 |
community_global_df_with_id = pd.DataFrame()
|
|
|
67 |
async def on_ready():
|
68 |
try:
|
69 |
global global_df
|
|
|
70 |
await asyncio.sleep(1.1)
|
71 |
print(f'Logged in as {bot.user.name}')
|
72 |
print(f"XP_PER_MESSAGE: {XP_PER_MESSAGE}")
|
|
|
75 |
global_df = test_merge
|
76 |
print(f"csv successfully retrieved: \n {global_df}")
|
77 |
|
|
|
|
|
|
|
|
|
|
|
78 |
# updates both leaderboards
|
79 |
#await remove_huggingfolks() # to initialize
|
80 |
#print(community_global_df_with_id)
|
|
|
112 |
def calculate_xp(level):
|
113 |
return (int(level ** 3))
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
async def add_exp(member_id):
|
117 |
try:
|