Commit
Β·
f3c3cd9
1
Parent(s):
834ab51
test auto reload
Browse files- app.py +31 -3
- assets/text_content.py +2 -0
- requirements.txt +2 -1
- src/filter_utils.py +2 -0
app.py
CHANGED
|
@@ -5,11 +5,30 @@ from gradio_rangeslider import RangeSlider
|
|
| 5 |
import calendar
|
| 6 |
import datetime
|
| 7 |
import numpy as np
|
|
|
|
|
|
|
| 8 |
|
| 9 |
from src.filter_utils import filter, filter_cols
|
| 10 |
from src.process_data import merge_data
|
| 11 |
import assets.text_content as tc
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Main Leaderboard containing everything
|
| 14 |
# text_leaderboard = pd.read_csv(os.path.join('assets', 'merged_data.csv'))
|
| 15 |
text_leaderboard = merge_data()
|
|
@@ -193,9 +212,9 @@ with llm_calc_app:
|
|
| 193 |
############# Modality selection checkbox ###############
|
| 194 |
with gr.Row():
|
| 195 |
multimodal_checkbox = gr.CheckboxGroup(
|
| 196 |
-
choices=[tc.SINGLE_IMG, tc.MULT_IMG, tc.AUDIO, tc.VIDEO],
|
| 197 |
value=[],
|
| 198 |
-
label="
|
| 199 |
)
|
| 200 |
|
| 201 |
|
|
@@ -339,4 +358,13 @@ with llm_calc_app:
|
|
| 339 |
|
| 340 |
llm_calc_app.load()
|
| 341 |
llm_calc_app.queue()
|
| 342 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import calendar
|
| 6 |
import datetime
|
| 7 |
import numpy as np
|
| 8 |
+
from huggingface_hub import HfApi
|
| 9 |
+
from apscheduler.schedulers.background import BackgroundScheduler
|
| 10 |
|
| 11 |
from src.filter_utils import filter, filter_cols
|
| 12 |
from src.process_data import merge_data
|
| 13 |
import assets.text_content as tc
|
| 14 |
|
| 15 |
+
"""
|
| 16 |
+
CONSTANTS
|
| 17 |
+
"""
|
| 18 |
+
# For restarting the gradio application every 24 Hrs
|
| 19 |
+
TIME = 10 # in seconds # Reload will not work locally - requires HFToken # The app launches locally as expected - only without the reload utility
|
| 20 |
+
|
| 21 |
+
"""
|
| 22 |
+
AUTO RESTART HF SPACE
|
| 23 |
+
"""
|
| 24 |
+
HF_TOKEN = os.environ.get("H4_TOKEN", None)
|
| 25 |
+
api = HfApi()
|
| 26 |
+
|
| 27 |
+
def restart_space():
|
| 28 |
+
api.restart_space(repo_id=tc.HF_REPO, token=HF_TOKEN)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
# Main Leaderboard containing everything
|
| 33 |
# text_leaderboard = pd.read_csv(os.path.join('assets', 'merged_data.csv'))
|
| 34 |
text_leaderboard = merge_data()
|
|
|
|
| 212 |
############# Modality selection checkbox ###############
|
| 213 |
with gr.Row():
|
| 214 |
multimodal_checkbox = gr.CheckboxGroup(
|
| 215 |
+
choices=[tc.TEXT, tc.SINGLE_IMG, tc.MULT_IMG, tc.AUDIO, tc.VIDEO],
|
| 216 |
value=[],
|
| 217 |
+
label="Modalities ππ·π§π¬",
|
| 218 |
)
|
| 219 |
|
| 220 |
|
|
|
|
| 358 |
|
| 359 |
llm_calc_app.load()
|
| 360 |
llm_calc_app.queue()
|
| 361 |
+
|
| 362 |
+
# Add scheduler to auto-restart the HF space at every TIME interval and update every component each time
|
| 363 |
+
scheduler = BackgroundScheduler()
|
| 364 |
+
scheduler.add_job(restart_space, 'interval', seconds=TIME)
|
| 365 |
+
scheduler.start()
|
| 366 |
+
|
| 367 |
+
# Log current start time and scheduled restart time
|
| 368 |
+
print(datetime.datetime.now())
|
| 369 |
+
print(f"Scheduled restart at {datetime.datetime.now() + datetime.timedelta(seconds=TIME)}")
|
| 370 |
+
|
assets/text_content.py
CHANGED
|
@@ -29,6 +29,7 @@ LICENSE_NAME = "License Name"
|
|
| 29 |
LICENSE_URL = "License URL"
|
| 30 |
SINGLE_IMG = "Single Image"
|
| 31 |
MULT_IMG = "Multi Image"
|
|
|
|
| 32 |
AUDIO = "Audio"
|
| 33 |
VIDEO = "Video"
|
| 34 |
INPUT = "Input $/1M tokens"
|
|
@@ -42,6 +43,7 @@ COMM = "Commercial"
|
|
| 42 |
|
| 43 |
TITLE = """<h1 align="center" id="space-title"> LLM Calculator βοΈβ‘ ππ°</h1>"""
|
| 44 |
|
|
|
|
| 45 |
# Date Picker (set as Dropdown until datetime object is fixed)
|
| 46 |
START_YEAR = "2020"
|
| 47 |
MONTH_MAP = {
|
|
|
|
| 29 |
LICENSE_URL = "License URL"
|
| 30 |
SINGLE_IMG = "Single Image"
|
| 31 |
MULT_IMG = "Multi Image"
|
| 32 |
+
TEXT = "Text-Only"
|
| 33 |
AUDIO = "Audio"
|
| 34 |
VIDEO = "Video"
|
| 35 |
INPUT = "Input $/1M tokens"
|
|
|
|
| 43 |
|
| 44 |
TITLE = """<h1 align="center" id="space-title"> LLM Calculator βοΈβ‘ ππ°</h1>"""
|
| 45 |
|
| 46 |
+
HF_REPO = "Koshti10/LLMCalc"
|
| 47 |
# Date Picker (set as Dropdown until datetime object is fixed)
|
| 48 |
START_YEAR = "2020"
|
| 49 |
MONTH_MAP = {
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
pandas==2.2.3
|
| 2 |
gradio_rangeslider==0.0.7
|
| 3 |
gradio==4.44.1
|
| 4 |
-
pycountry==24.6.1
|
|
|
|
|
|
| 1 |
pandas==2.2.3
|
| 2 |
gradio_rangeslider==0.0.7
|
| 3 |
gradio==4.44.1
|
| 4 |
+
pycountry==24.6.1
|
| 5 |
+
apscheduler==3.10.4
|
src/filter_utils.py
CHANGED
|
@@ -93,6 +93,8 @@ def filter(df, language_list, parameters, input_price, output_price, multimodal,
|
|
| 93 |
df = df[(df[tc.OUTPUT] >= output_price[0]) & (df[tc.OUTPUT] <= output_price[1])]
|
| 94 |
|
| 95 |
if not df.empty: # Check if df is non-empty
|
|
|
|
|
|
|
| 96 |
if tc.SINGLE_IMG in multimodal:
|
| 97 |
df = df[df[tc.SINGLE_IMG] == True]
|
| 98 |
if tc.MULT_IMG in multimodal:
|
|
|
|
| 93 |
df = df[(df[tc.OUTPUT] >= output_price[0]) & (df[tc.OUTPUT] <= output_price[1])]
|
| 94 |
|
| 95 |
if not df.empty: # Check if df is non-empty
|
| 96 |
+
if tc.TEXT in multimodal:
|
| 97 |
+
df = df[(df[tc.SINGLE_IMG] == False) & (df[tc.MULT_IMG] == False) & (df[tc.AUDIO] == False) & (df[tc.VIDEO] == False) ]
|
| 98 |
if tc.SINGLE_IMG in multimodal:
|
| 99 |
df = df[df[tc.SINGLE_IMG] == True]
|
| 100 |
if tc.MULT_IMG in multimodal:
|