Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
MODEL_NAME = "text"
|
| 6 |
+
HF_USER = "universalml"
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def prediction_function(input_file):
|
| 10 |
+
repo_id = HF_USER + "/" + MODEL_NAME
|
| 11 |
+
model = pipeline("text-classification", model=repo_id)
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
result = model(input_file)
|
| 15 |
+
predictions = {}
|
| 16 |
+
labels = []
|
| 17 |
+
for each_label in result:
|
| 18 |
+
predictions[each_label["label"]] = each_label["score"]
|
| 19 |
+
labels.append(each_label["label"])
|
| 20 |
+
result = predictions
|
| 21 |
+
except:
|
| 22 |
+
result = "no data provided!!"
|
| 23 |
+
|
| 24 |
+
return result
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def create_interface():
|
| 28 |
+
interface = gr.Interface(
|
| 29 |
+
fn=prediction_function,
|
| 30 |
+
inputs=gr.Textbox(label="Input text", type="text"),
|
| 31 |
+
outputs=gr.Label(num_top_classes=3),
|
| 32 |
+
title=MODEL_NAME,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
interface.launch(debug=True)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
create_interface()
|