Spaces:
Runtime error
Runtime error
File size: 1,201 Bytes
d50480b f1c1728 8a99a39 d50480b 8a99a39 f1c1728 84ffbea f7503c7 d50480b 8a99a39 f7503c7 d50480b f7503c7 c172233 d50480b f7503c7 243a0e8 f7503c7 |
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 |
import os
import spaces
import gradio as gr
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model=os.getenv('MODEL'))
@spaces.GPU(duration=120)
def classify(text, labels):
labels = labels.split(',')
if not text or not labels:
return []
result = classifier(text, candidate_labels=labels)
return list(zip(result['labels'], map(lambda x: round(x, 4), result['scores'])))
with gr.Blocks() as demo:
gr.Markdown("## Zero-Shot классификация")
with gr.Row():
with gr.Column(scale=2):
text_input = gr.Textbox(label="Текст для классификации", placeholder="Введите текст...")
labels_input = gr.Textbox(label="Классы (через запятую)", placeholder="Опишите классы через запятую...")
button = gr.Button("Classify")
with gr.Column(scale=1):
output = gr.Dataframe(headers=[" Класс ", "Вероятность"], label="Результаты классификации")
button.click(classify, inputs=[text_input, labels_input], outputs=output)
demo.launch()
|