hussain-shk commited on
Commit
cdf210b
1 Parent(s): 338abb1

updated and added trans api

Browse files
Files changed (1) hide show
  1. app.py +42 -9
app.py CHANGED
@@ -7,14 +7,47 @@ roberta_pipe = pipeline(
7
  return_all_scores = True
8
  )
9
 
10
- def analyse_sentiment(text):
11
- response = roberta_pipe(text)
12
- d = {}
13
- for i in response[0]:
14
- d[i['label'].lower()] = i['score']
15
- return d
16
 
17
- text = gr.Textbox(lines=5, placeholder="Enter Text to Get Sentiment",default="", label="Enter Text")
18
 
19
- iface = gr.Interface(fn=analyse_sentiment, inputs=[text], outputs="label", title='Roberta Sentiment Analysis')
20
- iface.launch(enable_queue=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ target
20
+ ]
21
+ }, timeout=None).json()
22
+ return response["data"][0]
23
+
24
+ def analyse_sentiment(text, source):
25
+ if source != "English":
26
+ text = trans(text, source, "English")
27
+ response = roberta_pipe(text)
28
+ d = {}
29
+ for i in response[0]:
30
+ d[i['label'].lower()] = i['score']
31
+ return d
32
+
33
+ languages = ["Assamese", "Bengali", "Gujarati", "Hindi", "Kannada","Malayalam", "Marathi", "Odia", "Punjabi", "Tamil", "Telugu", "English"]
34
+
35
+ input_text = gr.Textbox(placeholder="Enter a positive or negative sentence here...")
36
+ drop_down = gr.inputs.Dropdown(languages, type="value", default="English", label="Select Source Language")
37
+
38
+ examples = [["this book was a great book that i have read many times", "English"],
39
+ ["एक महान अमेरिकी लेखक का एक आकर्षक संग्रह" , "Hindi"],
40
+ ["हा आतापर्यंतचा सर्वात वाईट चित्रपट आहे यात शंका नाही", "Marathi"],
41
+ ["இந்த தயாரிப்பு ஆச்சரியமாக இருக்கிறது", "Tamil"],
42
+ ["તમારા માટે નહીં જો તમે વિના અવરોધે વીડિયો શોધી રહ્યા છો", "Gujrati"],]
43
+
44
+ demo = gr.Interface(
45
+ enable_queue=True,
46
+ fn=analyse_sentiment,
47
+ inputs=[input_text, drop_down],
48
+ outputs="label",
49
+ interpretation="default",
50
+ title='IndiSent: Multilingual Sentiment Analysis',
51
+ examples=examples)
52
+
53
+ demo.launch()