Spaces:
Running
Running
import gradio as gr | |
with open('materials/introduction.html', 'r', encoding='utf-8') as file: | |
html_description = file.read() | |
with gr.Blocks() as landing_interface: | |
gr.HTML(html_description) | |
with gr.Accordion("How to run this model locally", open=False): | |
gr.Markdown( | |
""" | |
## Installation | |
To use this model, you must install the GLiClass Python library: | |
``` | |
!pip install gliclass | |
``` | |
## Usage | |
Once you've downloaded the GLiClass library, you can import the GLiClassModel and ZeroShotClassificationPipeline classes. | |
""" | |
) | |
gr.Code( | |
''' | |
from gliclass import GLiClassModel, ZeroShotClassificationPipeline | |
from transformers import AutoTokenizer | |
model = GLiClassModel.from_pretrained("knowledgator/gliclass-small-v1") | |
tokenizer = AutoTokenizer.from_pretrained("knowledgator/gliclass-small-v1") | |
pipeline = ZeroShotClassificationPipeline(model, tokenizer, classification_type='multi-label', device='cuda:0') | |
text = "One day I will see the world!" | |
labels = ["travel", "dreams", "sport", "science", "politics"] | |
results = pipeline(text, labels, threshold=0.5)[0] #because we have one text | |
for result in results: | |
print(result["label"], "=>", result["score"]) | |
''', | |
language="python", | |
) |