Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,21 +6,39 @@ from threading import Timer
|
|
6 |
|
7 |
HUGGINGFACE_TOKEN = os.environ.get("HUGGINGFACE_TOKEN")
|
8 |
def get_available_free():
|
9 |
-
|
|
|
|
|
|
|
10 |
models_conclusion = {
|
11 |
"Model": [],
|
12 |
"API": [],
|
13 |
"Text Completion": [],
|
14 |
-
"Chat Completion": []
|
|
|
15 |
}
|
16 |
-
for m in models:
|
17 |
text_available = False
|
18 |
chat_available = False
|
|
|
|
|
|
|
19 |
pro_sub = False
|
20 |
try:
|
21 |
InferenceClient(m, timeout=10, token=HUGGINGFACE_TOKEN).text_generation("Hi.", max_new_tokens=1)
|
22 |
text_available = True
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
chat_available = True
|
25 |
except Exception as e:
|
26 |
print(e)
|
@@ -36,6 +54,7 @@ def get_available_free():
|
|
36 |
models_conclusion["API"].append("Free" if chat_available or text_available else ("Pro Subscription" if pro_sub else "Not Responding"))
|
37 |
models_conclusion["Chat Completion"].append("---" if (pro_sub or (not chat_available and not text_available)) else ("β" if chat_available else "β"))
|
38 |
models_conclusion["Text Completion"].append("---" if (pro_sub or (not chat_available and not text_available)) else ("β" if text_available else "β"))
|
|
|
39 |
pd.DataFrame(models_conclusion).to_csv("data.csv", index=False)
|
40 |
return models_conclusion
|
41 |
|
@@ -48,7 +67,7 @@ def update_data():
|
|
48 |
df['Text Completion'] = df['Text Completion'].map(status_mapping)
|
49 |
df['Chat Completion'] = df['Chat Completion'].map(status_mapping)
|
50 |
|
51 |
-
df = df.sort_values(by=['API', 'Text Completion', 'Chat Completion'])
|
52 |
|
53 |
df['Text Completion'] = df['Text Completion'].map({v: k for k, v in status_mapping.items()})
|
54 |
df['Chat Completion'] = df['Chat Completion'].map({v: k for k, v in status_mapping.items()})
|
@@ -62,7 +81,7 @@ def display_table(search_query=""):
|
|
62 |
else:
|
63 |
filtered_df = df
|
64 |
|
65 |
-
styled_df = filtered_df.style.apply(apply_row_styles, axis=1, subset=["Model", "API", "Text Completion", "Chat Completion"])
|
66 |
return styled_df
|
67 |
|
68 |
def apply_row_styles(row):
|
@@ -71,7 +90,8 @@ def apply_row_styles(row):
|
|
71 |
color_status(api_value, row["Model"]),
|
72 |
color_status(api_value, row["API"]),
|
73 |
color_status(api_value, row["Text Completion"]),
|
74 |
-
color_status(api_value, row["Chat Completion"])
|
|
|
75 |
]
|
76 |
|
77 |
def color_status(api_value, cell_value):
|
|
|
6 |
|
7 |
HUGGINGFACE_TOKEN = os.environ.get("HUGGINGFACE_TOKEN")
|
8 |
def get_available_free():
|
9 |
+
models_dict = InferenceClient(token=HUGGINGFACE_TOKEN).list_deployed_models("text-generation-inference")
|
10 |
+
models = models_dict['text-generation'] + models_dict['text2text-generation'] #token=HUGGINGFACE_TOKEN
|
11 |
+
models_vision = models_dict['image-text-to-text']
|
12 |
+
|
13 |
models_conclusion = {
|
14 |
"Model": [],
|
15 |
"API": [],
|
16 |
"Text Completion": [],
|
17 |
+
"Chat Completion": [],
|
18 |
+
"Vision": []
|
19 |
}
|
20 |
+
for m in models + models_vision:
|
21 |
text_available = False
|
22 |
chat_available = False
|
23 |
+
vision_available = False
|
24 |
+
if m in models_vision:
|
25 |
+
vision_available = True
|
26 |
pro_sub = False
|
27 |
try:
|
28 |
InferenceClient(m, timeout=10, token=HUGGINGFACE_TOKEN).text_generation("Hi.", max_new_tokens=1)
|
29 |
text_available = True
|
30 |
+
except Exception as e:
|
31 |
+
print(e)
|
32 |
+
if e and "Model requires a Pro subscription" in str(e):
|
33 |
+
pro_sub = True
|
34 |
+
if e and "Rate limit reached" in str(e):
|
35 |
+
print("Rate Limited!!")
|
36 |
+
if os.path.exists("data.csv"):
|
37 |
+
print("Loading data from file...")
|
38 |
+
return pd.read_csv("data.csv").to_dict(orient='list')
|
39 |
+
return []
|
40 |
+
try:
|
41 |
+
InferenceClient(m, timeout=10).chat_completion(messages=[{'role': 'user', 'content': 'Hi.'}], max_tokens=1) #token=HUGGINGFACE_TOKEN
|
42 |
chat_available = True
|
43 |
except Exception as e:
|
44 |
print(e)
|
|
|
54 |
models_conclusion["API"].append("Free" if chat_available or text_available else ("Pro Subscription" if pro_sub else "Not Responding"))
|
55 |
models_conclusion["Chat Completion"].append("---" if (pro_sub or (not chat_available and not text_available)) else ("β" if chat_available else "β"))
|
56 |
models_conclusion["Text Completion"].append("---" if (pro_sub or (not chat_available and not text_available)) else ("β" if text_available else "β"))
|
57 |
+
models_conclusion["Vision"].append("---" if (pro_sub or (not chat_available and not text_available)) else ("β" if vision_available else "β"))
|
58 |
pd.DataFrame(models_conclusion).to_csv("data.csv", index=False)
|
59 |
return models_conclusion
|
60 |
|
|
|
67 |
df['Text Completion'] = df['Text Completion'].map(status_mapping)
|
68 |
df['Chat Completion'] = df['Chat Completion'].map(status_mapping)
|
69 |
|
70 |
+
df = df.sort_values(by=['API', 'Text Completion', 'Chat Completion', 'Vision'])
|
71 |
|
72 |
df['Text Completion'] = df['Text Completion'].map({v: k for k, v in status_mapping.items()})
|
73 |
df['Chat Completion'] = df['Chat Completion'].map({v: k for k, v in status_mapping.items()})
|
|
|
81 |
else:
|
82 |
filtered_df = df
|
83 |
|
84 |
+
styled_df = filtered_df.style.apply(apply_row_styles, axis=1, subset=["Model", "API", "Text Completion", "Chat Completion", "Vision"])
|
85 |
return styled_df
|
86 |
|
87 |
def apply_row_styles(row):
|
|
|
90 |
color_status(api_value, row["Model"]),
|
91 |
color_status(api_value, row["API"]),
|
92 |
color_status(api_value, row["Text Completion"]),
|
93 |
+
color_status(api_value, row["Chat Completion"]),
|
94 |
+
color_status(api_value, row["Vision"])
|
95 |
]
|
96 |
|
97 |
def color_status(api_value, cell_value):
|