Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,14 +4,12 @@ import pandas as pd
|
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
from threading import Timer
|
| 6 |
from tqdm import tqdm
|
|
|
|
| 7 |
|
| 8 |
-
HUGGINGFACE_TOKEN =os.environ.get("HUGGINGFACE_TOKEN")
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# print("Loading data from file...")
|
| 13 |
-
return pd.read_csv("data.csv").to_dict(orient='list')
|
| 14 |
-
|
| 15 |
models_dict = InferenceClient(token=HUGGINGFACE_TOKEN).list_deployed_models("text-generation-inference")
|
| 16 |
models = models_dict['text-generation'] + models_dict['text2text-generation']
|
| 17 |
models_vision = models_dict['image-text-to-text']
|
|
@@ -25,7 +23,7 @@ def get_available_free(use_cache = False):
|
|
| 25 |
"Vision": []
|
| 26 |
}
|
| 27 |
|
| 28 |
-
all_models = list(set(models + models_vision + models_others))
|
| 29 |
for m in tqdm(all_models):
|
| 30 |
text_available = False
|
| 31 |
chat_available = False
|
|
@@ -41,11 +39,8 @@ def get_available_free(use_cache = False):
|
|
| 41 |
if e and "Model requires a Pro subscription" in str(e):
|
| 42 |
pro_sub = True
|
| 43 |
if e and "Rate limit reached" in str(e):
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
# print("Loading data from file...")
|
| 47 |
-
return pd.read_csv(str(os.getcwd())+"/data.csv").to_dict(orient='list')
|
| 48 |
-
return []
|
| 49 |
try:
|
| 50 |
InferenceClient(m, timeout=10).chat_completion(messages=[{'role': 'user', 'content': 'Hi.'}], max_tokens=1)
|
| 51 |
chat_available = True
|
|
@@ -54,11 +49,8 @@ def get_available_free(use_cache = False):
|
|
| 54 |
if e and "Model requires a Pro subscription" in str(e):
|
| 55 |
pro_sub = True
|
| 56 |
if e and "Rate limit reached" in str(e):
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# print("Loading data from file...")
|
| 60 |
-
return pd.read_csv(str(os.getcwd())+"/data.csv").to_dict(orient='list')
|
| 61 |
-
return []
|
| 62 |
models_conclusion["Model"].append(m)
|
| 63 |
models_conclusion["API"].append("Free" if chat_available or text_available else ("Pro Subscription" if pro_sub else "Not Responding"))
|
| 64 |
models_conclusion["Chat Completion"].append("---" if (pro_sub or (not chat_available and not text_available)) else ("β" if chat_available else "β"))
|
|
@@ -67,6 +59,14 @@ def get_available_free(use_cache = False):
|
|
| 67 |
pd.DataFrame(models_conclusion).to_csv(str(os.getcwd())+"/data.csv", index=False)
|
| 68 |
return models_conclusion
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def update_data(use_cache = False):
|
| 71 |
data = get_available_free(use_cache)
|
| 72 |
df = pd.DataFrame(data)
|
|
@@ -157,11 +157,11 @@ print(response)
|
|
| 157 |
```
|
| 158 |
"""
|
| 159 |
first_run = True
|
|
|
|
| 160 |
with gr.Blocks() as demo:
|
| 161 |
gr.Markdown("## HF Serverless LLM Inference API Status")
|
| 162 |
gr.Markdown(description)
|
| 163 |
search_box = gr.Textbox(label="Search for a model", placeholder="Type model name here...")
|
| 164 |
-
gr.Markdown("### Cached Endpoints")
|
| 165 |
filter_box = gr.CheckboxGroup(choices=["Free", "Pro Subscription", "Not Responding", "Text Completion", "Chat Completion", "Vision"], label="Filters")
|
| 166 |
table = gr.Dataframe(value=display_table(use_cache=True), headers="keys")
|
| 167 |
|
|
|
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
from threading import Timer
|
| 6 |
from tqdm import tqdm
|
| 7 |
+
import time
|
| 8 |
|
| 9 |
+
HUGGINGFACE_TOKEN = os.environ.get("HUGGINGFACE_TOKEN")
|
| 10 |
+
|
| 11 |
+
def loop_query_data():
|
| 12 |
+
global all_models
|
|
|
|
|
|
|
|
|
|
| 13 |
models_dict = InferenceClient(token=HUGGINGFACE_TOKEN).list_deployed_models("text-generation-inference")
|
| 14 |
models = models_dict['text-generation'] + models_dict['text2text-generation']
|
| 15 |
models_vision = models_dict['image-text-to-text']
|
|
|
|
| 23 |
"Vision": []
|
| 24 |
}
|
| 25 |
|
| 26 |
+
all_models = list(set(all_models + models + models_vision + models_others))
|
| 27 |
for m in tqdm(all_models):
|
| 28 |
text_available = False
|
| 29 |
chat_available = False
|
|
|
|
| 39 |
if e and "Model requires a Pro subscription" in str(e):
|
| 40 |
pro_sub = True
|
| 41 |
if e and "Rate limit reached" in str(e):
|
| 42 |
+
print("Rate Limited, waiting 1 hour...")
|
| 43 |
+
time.sleep(60*60)
|
|
|
|
|
|
|
|
|
|
| 44 |
try:
|
| 45 |
InferenceClient(m, timeout=10).chat_completion(messages=[{'role': 'user', 'content': 'Hi.'}], max_tokens=1)
|
| 46 |
chat_available = True
|
|
|
|
| 49 |
if e and "Model requires a Pro subscription" in str(e):
|
| 50 |
pro_sub = True
|
| 51 |
if e and "Rate limit reached" in str(e):
|
| 52 |
+
print("Rate Limited, waiting 1 hour...")
|
| 53 |
+
time.sleep(60*60)
|
|
|
|
|
|
|
|
|
|
| 54 |
models_conclusion["Model"].append(m)
|
| 55 |
models_conclusion["API"].append("Free" if chat_available or text_available else ("Pro Subscription" if pro_sub else "Not Responding"))
|
| 56 |
models_conclusion["Chat Completion"].append("---" if (pro_sub or (not chat_available and not text_available)) else ("β" if chat_available else "β"))
|
|
|
|
| 59 |
pd.DataFrame(models_conclusion).to_csv(str(os.getcwd())+"/data.csv", index=False)
|
| 60 |
return models_conclusion
|
| 61 |
|
| 62 |
+
def get_available_free(use_cache = False):
|
| 63 |
+
if use_cache:
|
| 64 |
+
if os.path.exists(str(os.getcwd())+"/data.csv"):
|
| 65 |
+
# print("Loading data from file...")
|
| 66 |
+
return pd.read_csv("data.csv").to_dict(orient='list')
|
| 67 |
+
else:
|
| 68 |
+
return loop_query_data()
|
| 69 |
+
|
| 70 |
def update_data(use_cache = False):
|
| 71 |
data = get_available_free(use_cache)
|
| 72 |
df = pd.DataFrame(data)
|
|
|
|
| 157 |
```
|
| 158 |
"""
|
| 159 |
first_run = True
|
| 160 |
+
all_models = []
|
| 161 |
with gr.Blocks() as demo:
|
| 162 |
gr.Markdown("## HF Serverless LLM Inference API Status")
|
| 163 |
gr.Markdown(description)
|
| 164 |
search_box = gr.Textbox(label="Search for a model", placeholder="Type model name here...")
|
|
|
|
| 165 |
filter_box = gr.CheckboxGroup(choices=["Free", "Pro Subscription", "Not Responding", "Text Completion", "Chat Completion", "Vision"], label="Filters")
|
| 166 |
table = gr.Dataframe(value=display_table(use_cache=True), headers="keys")
|
| 167 |
|