Spaces:
Runtime error
Runtime error
File size: 1,177 Bytes
9e2cb0a 7d33fb7 709816c 7d33fb7 9c89421 4fc4a5d 9c89421 7d33fb7 a93e5c6 7d33fb7 ba70565 9e2cb0a dce65c7 9e2cb0a ba70565 |
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 31 32 33 34 35 36 37 38 39 |
import gradio as gr
import torch
from datasets import load_dataset
dataset = load_dataset("zeroshot/twitter-financial-news-sentiment", )
intf = gr.Interface(fn=None, input=None, outputs=dataset['train'][:10])
intf.launch()
from transformers import AutoModelForSequenceClassification, AutoTokenizer
model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased")
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
def sentiment_score(review):
tokens = tokenizer.encode(review, return_tensors='pt')
result = model(tokens)
return int(torch.argmax(result.logits))
dataset['sentiment'] = dataset['text'].apply(lambda x: sentiment_score(x[:512]))
"""
categories = ('Car in good condition','Damaged Car')
def is_car(x) : return x[0].isupper()
def image_classifier(img):
pred,index,probs = learn.predict(img)
return dict(zip(categories, map(float,probs)))
# image = gr.inputs.Image(shape=(192,192))
image = gr.components.Image(shape=(192,192))
label = gr.components.Label()
examples = ['./car.jpg','./crash.jpg','./carf.jpg']
intf = gr.Interface(fn= image_classifier,inputs=image,outputs=label,examples=examples)
intf.launch()""" |