sandeepmajumdar commited on
Commit
d835976
·
1 Parent(s): 35ee008
Files changed (1) hide show
  1. app.py +120 -0
app.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Sentiment analysis interface
5
+ sa_examples = [
6
+ 'the food delivered was stale',
7
+ 'i like your shirt',
8
+ 'this is not the way to work',
9
+ ]
10
+
11
+ sa_app = gr.Interface.load(
12
+ 'huggingface/distilbert-base-uncased-finetuned-sst-2-english',
13
+ title='Sentiment Analysis',
14
+ examples=sa_examples,
15
+ description='Type your sentence here and Submit',
16
+ )
17
+
18
+ # Text Generation
19
+ tg_examples = [
20
+ 'I want to feel',
21
+ 'It is possible to',
22
+ 'When the world seems'
23
+ ]
24
+
25
+ tg_app = gr.Interface.load(
26
+ 'huggingface/distilgpt2',
27
+ title='Text Generation',
28
+ examples=tg_examples,
29
+ description="Write an incomplete sentence and submit",
30
+ )
31
+
32
+ # Fill Mask
33
+ fm_examples = [
34
+ 'Do you know how much I <mask> you?',
35
+ 'When we went to the forest, it <mask> raining',
36
+ ]
37
+
38
+ fm_app = gr.Interface.load(
39
+ 'huggingface/distilroberta-base',
40
+ title='Fill In The Blank',
41
+ examples=fm_examples,
42
+ description="Write a sentence with a missing word using \<mask\>",
43
+ )
44
+
45
+ # Named Entity Recognition
46
+ ner_examples = [
47
+ 'My name is Doug and I live in Delhi',
48
+ 'Vishal works at Google',
49
+ ]
50
+
51
+ ner_app = gr.Interface.load(
52
+ 'huggingface/dbmdz/bert-large-cased-finetuned-conll03-english',
53
+ title='Named Entity Recognition',
54
+ examples=ner_examples,
55
+ description="Write a sentence with a name, place, organization, etc and I'll try to reveal them",
56
+ )
57
+
58
+ # Summarization
59
+ sum_examples = [
60
+ '''Television is one of the many wonders of modern science and technology. It was invented in England by the Scottish scientist J.N. Baird
61
+ in 1928 and the British Broadcasting Corporation was the first to broadcast television images in 1929. Previously the radio helped us
62
+ hear things from far and near. spread information and knowledge from one corner of the globe to another. But all this was done through
63
+ sound only. But television combined visual images with sound. Today we can watch games, shows, and song and dance programs from all
64
+ corners of the world while sitting at our own homes. TV can be used for educating the masses, for bringing to us the latest pieces of
65
+ information audio-visually and can provide us all kinds of entertainment even in color. But as in all things, too much televiewing may
66
+ prove harmful. In many cases, the habit of watching TV has an adverse effect on the study habits of the young. When we read books, we
67
+ have to use our intelligence and imagination. But in most cases, TV watching is a passive thing. It may dull our imagination and
68
+ intelligence.''',
69
+ ]
70
+
71
+ sum_app = gr.Interface.load(
72
+ 'huggingface/sshleifer/distilbart-cnn-12-6',
73
+ title='Text Summarization',
74
+ examples=sum_examples,
75
+ description="Copy and dump a long paragraph here for summarization, or click the example below",
76
+ )
77
+
78
+ # Translation to Hindi
79
+ trans_examples = [
80
+ 'I want to go home',
81
+ "i will go to the station tomorrow",
82
+ ]
83
+
84
+ trans_app = gr.Interface.load(
85
+ 'huggingface/Helsinki-NLP/opus-mt-en-hi',
86
+ title='Translate From English to Hindi',
87
+ examples=trans_examples,
88
+ description="Write a sentence to translate from English to Hindi",
89
+ )
90
+
91
+ # Text to Speech
92
+ tts_examples = [
93
+ "How do you do?",
94
+ 'i thought we were supposed to go to the park'
95
+ ]
96
+
97
+ tts_app = gr.Interface.load(
98
+ "huggingface/facebook/fastspeech2-en-ljspeech",
99
+ title='Text to Speech',
100
+ examples=tts_examples,
101
+ description="Give me something to say!",
102
+ )
103
+
104
+ # Speech to Text
105
+ stt_app = gr.Interface.load(
106
+ "huggingface/facebook/wav2vec2-base-960h",
107
+ title='Speech to Text',
108
+ inputs="mic",
109
+ description="Let me try to guess what you're saying! Stop the recording button before submitting.",
110
+ )
111
+
112
+ with gr.Blocks() as demo:
113
+ gr.Markdown("# App For Various NLP Tasks (use landscape on phone)")
114
+ gr.TabbedInterface([sa_app, tg_app, fm_app, ner_app, sum_app, trans_app, tts_app, stt_app],
115
+ ["Sentiment Analysis", "Text Generation", "Fill Blank", "Named Entity", "Summary",
116
+ "Translation", "Text to Speech", "Speech to Text"]
117
+ )
118
+
119
+ if __name__ == "__main__":
120
+ demo.launch()