Spaces:
Sleeping
Sleeping
from transformers import pipeline | |
import gradio as gr | |
MODEL_NAME = "prpdtff" | |
HF_USER = "universalml" | |
def prediction_function(input_file): | |
repo_id = HF_USER + "/" + MODEL_NAME | |
model = pipeline("text-classification", model=repo_id) | |
try: | |
result = model(input_file) | |
predictions = {} | |
labels = [] | |
for each_label in result: | |
predictions[each_label["label"]] = each_label["score"] | |
labels.append(each_label["label"]) | |
result = predictions | |
except: | |
result = "no data provided!!" | |
return result | |
def create_interface(): | |
interface = gr.Interface( | |
fn=prediction_function, | |
inputs=gr.Textbox(label="Input text", type="text"), | |
outputs=gr.Label(num_top_classes=3), | |
title=MODEL_NAME, | |
) | |
interface.launch(debug=True) | |
create_interface() | |