Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import os
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
os.environ["WANDB_DISABLED"] = "true"
|
| 6 |
+
|
| 7 |
+
from datasets import load_dataset, load_metric
|
| 8 |
+
from transformers import (
|
| 9 |
+
AutoConfig,
|
| 10 |
+
AutoModelForSequenceClassification,
|
| 11 |
+
AutoTokenizer,
|
| 12 |
+
TrainingArguments,
|
| 13 |
+
logging,
|
| 14 |
+
pipeline
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# model_name =
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 24 |
+
|
| 25 |
+
# config = AutoConfig.from_pretrained(model_name)
|
| 26 |
+
|
| 27 |
+
# pipe = pipeline("text-classification")
|
| 28 |
+
|
| 29 |
+
# pipe("This restaurant is awesome")
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# Question answering pipeline, specifying the checkpoint identifier
|
| 35 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 36 |
+
pretrained_model_name_or_path= "thak123/Cro-Frida",
|
| 37 |
+
num_labels=3,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
analyzer = pipeline(
|
| 42 |
+
|
| 43 |
+
"sentiment-analysis", model=model, tokenizer="EMBEDDIA/crosloengual-bert"
|
| 44 |
+
|
| 45 |
+
)
|
| 46 |
+
def predict_sentiment(x):
|
| 47 |
+
return analyzer(x)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
interface = gr.Interface(
|
| 54 |
+
fn=predict_sentiment,
|
| 55 |
+
inputs='text',
|
| 56 |
+
outputs=['label'],
|
| 57 |
+
title='Latvian Twitter Sentiment Analysis',
|
| 58 |
+
examples= ["Es mīlu Tevi","Es ienīstu kafiju"],
|
| 59 |
+
description='Get the positive/neutral/negative sentiment for the given input.'
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
interface.launch(inline = False)
|