hussain-shk commited on
Commit
2be76ff
·
1 Parent(s): 9b65fb5
Files changed (1) hide show
  1. app.py +20 -16
app.py CHANGED
@@ -1,3 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from transformers import pipeline
2
  import gradio as gr
3
  roberta_pipe = pipeline(
@@ -7,22 +24,9 @@ roberta_pipe = pipeline(
7
  return_all_scores = True
8
  )
9
 
10
- import requests
11
-
12
- TRANS_API = "https://hussain-shk-indictrans-indic2english.hf.space/run/predict"
13
-
14
- def trans(text: str, source:str, target:str):
15
- response = requests.post(TRANS_API, json={
16
- "data": [
17
- text,
18
- source,
19
- ]
20
- }, timeout=None).json()
21
- return response["data"][0]
22
-
23
  def analyse_sentiment(text, source):
24
  if source != "English":
25
- text = trans(text, source, "English")
26
  response = roberta_pipe(text)
27
  d = {}
28
  for i in response[0]:
@@ -38,7 +42,7 @@ examples = [["this book was a great book that i have read many times", "English"
38
  ["एक महान अमेरिकी लेखक का एक आकर्षक संग्रह" , "Hindi"],
39
  ["हा आतापर्यंतचा सर्वात वाईट चित्रपट आहे यात शंका नाही", "Marathi"],
40
  ["இந்த தயாரிப்பு ஆச்சரியமாக இருக்கிறது", "Tamil"],
41
- ["તમારા માટે નહીં જો તમે વિના અવરોધે વીડિયો શોધી રહ્યા છો", "Gujrati"],]
42
 
43
  demo = gr.Interface(
44
  enable_queue=True,
@@ -49,4 +53,4 @@ demo = gr.Interface(
49
  title='IndiSent: Multilingual Sentiment Analysis',
50
  examples=examples)
51
 
52
- demo.launch()
 
1
+ import os
2
+ import gradio as gr
3
+
4
+ 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"
5
+ os.system(download)
6
+ os.system('unzip /home/user/app/indic-en.zip')
7
+
8
+ from fairseq import checkpoint_utils, distributed_utils, options, tasks, utils
9
+ from inference.engine import Model
10
+ indic2en_model = Model(expdir='/home/user/app/indic-en')
11
+
12
+ INDIC = {"Assamese": "as", "Bengali": "bn", "Gujarati": "gu", "Hindi": "hi","Kannada": "kn","Malayalam": "ml", "Marathi": "mr", "Odia": "or","Punjabi": "pa","Tamil": "ta", "Telugu" : "te"}
13
+
14
+
15
+ def translate(text, lang):
16
+ return indic2en_model.translate_paragraph(text, INDIC[lang], 'en')
17
+
18
  from transformers import pipeline
19
  import gradio as gr
20
  roberta_pipe = pipeline(
 
24
  return_all_scores = True
25
  )
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  def analyse_sentiment(text, source):
28
  if source != "English":
29
+ text = translate(text, source, "English")
30
  response = roberta_pipe(text)
31
  d = {}
32
  for i in response[0]:
 
42
  ["एक महान अमेरिकी लेखक का एक आकर्षक संग्रह" , "Hindi"],
43
  ["हा आतापर्यंतचा सर्वात वाईट चित्रपट आहे यात शंका नाही", "Marathi"],
44
  ["இந்த தயாரிப்பு ஆச்சரியமாக இருக்கிறது", "Tamil"],
45
+ ["તમારા માટે નહીં જો તમે વિના અવરોધે વીડિયો શોધી રહ્યા છો", "Gujarati"],]
46
 
47
  demo = gr.Interface(
48
  enable_queue=True,
 
53
  title='IndiSent: Multilingual Sentiment Analysis',
54
  examples=examples)
55
 
56
+ demo.launch(share = True, debug=True, inline=True)