Spaces:
Sleeping
Sleeping
File size: 1,698 Bytes
ec0c384 e80b69d ec0c384 |
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 |
from typing import List
import gradio as gr
from transformers import AutoModel, AutoTokenizer
from huggingface_hub import list_models
def get_collection_models(collection_name: str) -> List[str]:
"""Get a list of models from a specific Hugging Face collection."""
models = list_models(author="de-Rodrigo",
filter=f"collections:{collection_name}")
models_nofilter = list_models(author="de-Rodrigo")
print("")
print(models_nofilter)
print("")
model_names = [model.modelId for model in models]
return model_names
def load_model(model_name: str):
"""Load a model from Hugging Face Hub."""
model = AutoModel.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
return model, tokenizer
# Example processing function
def process_input(text: str, model_name: str) -> str:
model, tokenizer = load_model(model_name)
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
return f"Processed output with {model_name}"
# Create Gradio interface
def create_interface(collection_name: str):
iface = gr.Interface(
fn=process_input,
inputs=[
gr.Textbox(lines=2, placeholder="Enter some text", label="Input Text"),
gr.Dropdown(choices=get_collection_models(collection_name), label="Select Model")
],
outputs=gr.Textbox(label="Model Output"),
title="Hugging Face Model Selector from Collection",
description=f"Select a model from the '{collection_name}'.")
return iface
# Specify the name of your collection
collection_name = "VrDU-Doctor"
iface = create_interface(collection_name)
iface.launch()
|