Spaces:
Sleeping
Sleeping
Shashank Shekher commited on
Commit ·
4899689
1
Parent(s): e06f799
Get all models summary
Browse files- Dockerfile +8 -0
- app.py +52 -0
- requirements.txt +2 -0
Dockerfile
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
+
|
| 3 |
+
# Upgrade pip
|
| 4 |
+
RUN pip install --upgrade pip
|
| 5 |
+
|
| 6 |
+
# Install dependencies from requirements.txt
|
| 7 |
+
COPY requirements.txt /tmp/requirements.txt
|
| 8 |
+
RUN pip install --no-cache-dir -r /tmp/requirements.txt
|
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import HfApi
|
| 3 |
+
|
| 4 |
+
def fetch_model_info(api_token):
|
| 5 |
+
# Initialize API
|
| 6 |
+
api = HfApi()
|
| 7 |
+
|
| 8 |
+
# Authenticate using the provided token
|
| 9 |
+
user = api.whoami(api_token)
|
| 10 |
+
username = user["name"]
|
| 11 |
+
|
| 12 |
+
# Get models accessible to the user
|
| 13 |
+
models = api.list_models(author=username)
|
| 14 |
+
|
| 15 |
+
# Prepare data for the table
|
| 16 |
+
data = []
|
| 17 |
+
for model in models:
|
| 18 |
+
model_name = model.modelId
|
| 19 |
+
model_version = model.cardData.get("library_name", "Unknown")
|
| 20 |
+
parameter_count = model.cardData.get("parameters", "Unknown")
|
| 21 |
+
model_path = f"https://huggingface.co/{model_name}"
|
| 22 |
+
data.append([model_name, model_version, parameter_count, model_path])
|
| 23 |
+
|
| 24 |
+
return data
|
| 25 |
+
|
| 26 |
+
def display_models(api_token):
|
| 27 |
+
try:
|
| 28 |
+
# Fetch model info
|
| 29 |
+
models_data = fetch_model_info(api_token)
|
| 30 |
+
|
| 31 |
+
# Create HTML table
|
| 32 |
+
table_html = "<table border='1' style='border-collapse:collapse;width:100%;'>"
|
| 33 |
+
table_html += "<tr><th>Model Name</th><th>Version</th><th>Parameter Count</th><th>Path</th></tr>"
|
| 34 |
+
for row in models_data:
|
| 35 |
+
table_html += f"<tr><td>{row[0]}</td><td>{row[1]}</td><td>{row[2]}</td><td><a href='{row[3]}' target='_blank'>Link</a></td></tr>"
|
| 36 |
+
table_html += "</table>"
|
| 37 |
+
|
| 38 |
+
return table_html
|
| 39 |
+
except Exception as e:
|
| 40 |
+
return f"Error fetching models: {e}"
|
| 41 |
+
|
| 42 |
+
# Gradio Interface
|
| 43 |
+
with gr.Blocks() as demo:
|
| 44 |
+
gr.Markdown("### Hugging Face Model Information")
|
| 45 |
+
api_token_input = gr.Textbox(label="Hugging Face API Token", type="password")
|
| 46 |
+
output_html = gr.HTML()
|
| 47 |
+
fetch_button = gr.Button("Fetch Models")
|
| 48 |
+
|
| 49 |
+
fetch_button.click(display_models, inputs=[api_token_input], outputs=[output_html])
|
| 50 |
+
|
| 51 |
+
# Launch the app
|
| 52 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
huggingface_hub
|