Spaces:
Runtime error
Runtime error
| import os | |
| import gradio as gr | |
| download="wget --load-cookies /tmp/cookies.txt \"https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1-hzy09qi-OEogyge7rQG79K7iV4xsNWa' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\\n/p')&id=1-hzy09qi-OEogyge7rQG79K7iV4xsNWa\" -O indic-en.zip && rm -rf /tmp/cookies.txt" | |
| os.system(download) | |
| os.system('unzip /home/user/app/indic-en.zip') | |
| from fairseq import checkpoint_utils, distributed_utils, options, tasks, utils | |
| from inference.engine import Model | |
| indic2en_model = Model(expdir='/home/user/app/indic-en') | |
| INDIC = {"Assamese": "as", "Bengali": "bn", "Gujarati": "gu", "Hindi": "hi","Kannada": "kn","Malayalam": "ml", "Marathi": "mr", "Odia": "or","Punjabi": "pa","Tamil": "ta", "Telugu" : "te"} | |
| def translate(text, lang): | |
| return indic2en_model.translate_paragraph(text, INDIC[lang], 'en') | |
| 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 | |
| ) | |
| def analyse_sentiment(text, source): | |
| if source != "English": | |
| text = translate(text, source) | |
| 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"], | |
| ["તમારા માટે નહીં જો તમે વિના અવરોધે વીડિયો શોધી રહ્યા છો", "Gujarati"],] | |
| 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() |