Spaces:
Sleeping
Sleeping
test
Browse files
app.py
CHANGED
@@ -1,24 +1,55 @@
|
|
1 |
import gradio as gr
|
2 |
-
import requests
|
3 |
-
import json
|
4 |
import logging
|
5 |
from optimum.neuron import utils
|
6 |
-
|
7 |
|
8 |
# Set up logging
|
9 |
logging.basicConfig(level=logging.INFO)
|
10 |
|
11 |
-
def get_model_info(model_id
|
|
|
|
|
|
|
12 |
config_list = utils.get_hub_cached_entries(model_id=model_id, mode="inference")
|
13 |
return config_list
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
|
|
23 |
if __name__ == "__main__":
|
24 |
-
iface
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
import logging
|
3 |
from optimum.neuron import utils
|
4 |
+
import os
|
5 |
|
6 |
# Set up logging
|
7 |
logging.basicConfig(level=logging.INFO)
|
8 |
|
9 |
+
def get_model_info(model_id):
|
10 |
+
"""Retrieve configuration details for a specific model."""
|
11 |
+
if not model_id:
|
12 |
+
return "No model selected"
|
13 |
config_list = utils.get_hub_cached_entries(model_id=model_id, mode="inference")
|
14 |
return config_list
|
15 |
|
16 |
+
def get_model_list():
|
17 |
+
"""Retrieve list of cached models."""
|
18 |
+
return utils.get_hub_cached_models(mode="inference")
|
19 |
+
|
20 |
+
def create_model_list_interface():
|
21 |
+
"""Create a Gradio interface with model list as clickable buttons."""
|
22 |
+
# Get the model list and sort alphabetically by full model ID
|
23 |
+
models = sorted(get_model_list(), key=lambda x: (x[1] + x[2]).lower())
|
24 |
+
|
25 |
+
print(models)
|
26 |
+
|
27 |
+
# Prepare model IDs for buttons
|
28 |
+
model_ids = [f"{org}/{name}" for (arch, org, name) in models]
|
29 |
+
|
30 |
+
# Create the interface
|
31 |
+
with gr.Blocks() as iface:
|
32 |
+
with gr.Tab("Model List"):
|
33 |
+
# Buttons
|
34 |
+
with gr.Row():
|
35 |
+
buttons = gr.Radio(
|
36 |
+
choices=model_ids,
|
37 |
+
label="Select a Model"
|
38 |
+
)
|
39 |
+
|
40 |
+
# Output for model details
|
41 |
+
output = gr.Textbox(label="Model Configuration", lines=20)
|
42 |
+
|
43 |
+
# Connect model selection to output
|
44 |
+
buttons.change(
|
45 |
+
fn=get_model_info,
|
46 |
+
inputs=buttons,
|
47 |
+
outputs=output
|
48 |
+
)
|
49 |
+
|
50 |
+
return iface
|
51 |
|
52 |
+
# Launch the interface
|
53 |
if __name__ == "__main__":
|
54 |
+
iface = create_model_list_interface()
|
55 |
+
iface.launch()
|