Spaces:
Runtime error
Runtime error
from transformers import pipeline | |
import gradio as gr | |
roberta_pipe = pipeline( | |
"sentiment-analysis", | |
model="siebert/sentiment-roberta-large-english", | |
tokenizer="siebert/sentiment-roberta-large-english", | |
return_all_scores = True | |
) | |
import requests | |
TRANS_API = "https://hussain-shk-indictrans-indic2english.hf.space/run/predict" | |
def trans(text: str, source:str, target:str): | |
response = requests.post(TRANS_API, json={ | |
"data": [ | |
text, | |
source, | |
target | |
] | |
}, timeout=None).json() | |
return response["data"][0] | |
def analyse_sentiment(text, source): | |
if source != "English": | |
text = trans(text, source, "English") | |
response = roberta_pipe(text) | |
d = {} | |
for i in response[0]: | |
d[i['label'].lower()] = i['score'] | |
return d | |
languages = ["Assamese", "Bengali", "Gujarati", "Hindi", "Kannada","Malayalam", "Marathi", "Odia", "Punjabi", "Tamil", "Telugu", "English"] | |
input_text = gr.Textbox(placeholder="Enter a positive or negative sentence here...") | |
drop_down = gr.inputs.Dropdown(languages, type="value", default="English", label="Select Source Language") | |
examples = [["this book was a great book that i have read many times", "English"], | |
["एक महान अमेरिकी लेखक का एक आकर्षक संग्रह" , "Hindi"], | |
["हा आतापर्यंतचा सर्वात वाईट चित्रपट आहे यात शंका नाही", "Marathi"], | |
["இந்த தயாரிப்பு ஆச்சரியமாக இருக்கிறது", "Tamil"], | |
["તમારા માટે નહીં જો તમે વિના અવરોધે વીડિયો શોધી રહ્યા છો", "Gujrati"],] | |
demo = gr.Interface( | |
enable_queue=True, | |
fn=analyse_sentiment, | |
inputs=[input_text, drop_down], | |
outputs="label", | |
interpretation="default", | |
title='IndiSent: Multilingual Sentiment Analysis', | |
examples=examples) | |
demo.launch() |