File size: 2,269 Bytes
dbf650d
a2e4df5
 
 
dbf650d
 
 
 
 
a2e4df5
dbf650d
 
 
e4d88e1
dbf650d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f5d9f7
21882d6
8e42039
a198ad1
dbf650d
a2e4df5
 
dbf650d
a2e4df5
82101b9
8c480b7
efb1933
 
 
 
 
 
dbf650d
21882d6
dbf650d
 
 
 
21882d6
dbf650d
 
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
import requests
import gradio as gr
from threading import Timer

def fetch_models():
    # Example URL, replace with the actual API endpoint
    url = "https://api.example.com/v1/models"
    headers = {
        "Authorization": f"Bearer {TOKEN}"
    }
    response = requests.get(url, headers=headers)
    response.raise_for_status()
    return response.json()

def loop_query_data():
    global all_models, first_run
    try:
        models_dict = fetch_models()
        models = models_dict.get('text-generation', []) + models_dict.get('text2text-generation', [])
        all_models = models
    except KeyError as e:
        print(f"KeyError: {e} not found in the models dictionary")
        all_models = []

def search_models(query, filters, use_cache=False):
    # Add your logic here to filter models based on the query and filters
    filtered_models = [model for model in all_models if query.lower() in model.lower()]
    # Apply additional filtering based on the 'filters' parameter
    return filtered_models

def display_table(use_cache=False):
    # Create a table display of models
    data = [{"Model Name": model} for model in all_models]
    return data

first_run = True
all_models = []
loop_query_data()

with gr.Blocks() as demo:
    gr.Markdown("## HF Serverless LLM Inference API Status")
    gr.Markdown("Description of the API")
    search_box = gr.Textbox(label="Search for a model", placeholder="Type model name here...")
    filter_box = gr.CheckboxGroup(choices=["Free", "Pro Subscription", "Not Responding", "Text Completion", "Chat Completion", "Vision"], label="Filters")
    table = gr.Dataframe(value=display_table(use_cache=True), headers="keys")

    def update_filters(query, filters):
        return search_models(query, filters, use_cache=True)

    search_box.change(fn=update_filters, inputs=[search_box, filter_box], outputs=table)
    filter_box.change(fn=update_filters, inputs=[search_box, filter_box], outputs=table)

    def update_every_two_hours(first_run):
        loop_query_data()
        search_models(search_box.value, [], use_cache=first_run)
        Timer(7200, update_every_two_hours, args=(False,)).start()  # 7200 seconds = 2 hours

    Timer(0, update_every_two_hours, args=(first_run,)).start()

demo.launch()