de-Rodrigo commited on
Commit
ec0c384
·
1 Parent(s): 3b401a8

Upload Basic App

Browse files
Files changed (2) hide show
  1. app.py +42 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+ import gradio as gr
3
+ from transformers import AutoModel, AutoTokenizer
4
+ from huggingface_hub import list_models
5
+
6
+ def get_collection_models(collection_name: str) -> List[str]:
7
+ """Get a list of models from a specific Hugging Face collection."""
8
+ models = list_models(author="de-Rodrigo",
9
+ filter=f"collections:{collection_name}")
10
+ model_names = [model.modelId for model in models]
11
+ return model_names
12
+
13
+ def load_model(model_name: str):
14
+ """Load a model from Hugging Face Hub."""
15
+ model = AutoModel.from_pretrained(model_name)
16
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
17
+ return model, tokenizer
18
+
19
+ # Example processing function
20
+ def process_input(text: str, model_name: str) -> str:
21
+ model, tokenizer = load_model(model_name)
22
+ inputs = tokenizer(text, return_tensors="pt")
23
+ outputs = model(**inputs)
24
+ return f"Processed output with {model_name}"
25
+
26
+ # Create Gradio interface
27
+ def create_interface(collection_name: str):
28
+ iface = gr.Interface(
29
+ fn=process_input,
30
+ inputs=[
31
+ gr.Textbox(lines=2, placeholder="Enter some text", label="Input Text"),
32
+ gr.Dropdown(choices=get_collection_models(collection_name), label="Select Model")
33
+ ],
34
+ outputs=gr.Textbox(label="Model Output"),
35
+ title="Hugging Face Model Selector from Collection",
36
+ description=f"Select a model from the '{collection_name}'.")
37
+ return iface
38
+
39
+ # Specify the name of your collection
40
+ collection_name = "VrDU-Doctor"
41
+ iface = create_interface(collection_name)
42
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ huggingface_hub=
4
+ torch
5
+ numpy
6
+ Pillo