HishamSaad commited on
Commit
6bbbf98
1 Parent(s): f0cc455

Create taps.py

Browse files
Files changed (1) hide show
  1. taps.py +47 -0
taps.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+ import numpy as np
4
+
5
+ def get_sentiment(text):
6
+ sentiment_pipeline=pipeline('sentiment-analysis')
7
+ result=sentiment_pipeline(text)
8
+ output = gr.Textbox(label="Output Box")
9
+
10
+ return result[0]['label'],result[0]['score']
11
+
12
+ def summraztion(text):
13
+ summary_pipe = pipeline('summarization',model="cnicu/t5-small-booksum")
14
+ result=summary_pipe(text)
15
+ output = gr.Textbox(label="Output Box")
16
+
17
+ return result[0]['summary_text']
18
+
19
+ def chat_bot(text,histroy):
20
+ chat_pip=pipeline('text-generation')
21
+ mes=chat_pip(text)
22
+
23
+ return mes[0]['generated_text']
24
+
25
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
26
+
27
+ def transcribe(audio):
28
+ sr, y = audio
29
+ y = y.astype(np.float32)
30
+ y /= np.max(np.abs(y))
31
+
32
+ return transcriber({"sampling_rate": sr, "raw": y})["text"]
33
+
34
+ Audio = gr.Interface(
35
+ transcribe,
36
+ gr.Audio(sources=["microphone"]),
37
+ "text",
38
+ )
39
+
40
+ sentiment_a = gr.Interface(fn=get_sentiment , inputs=gr.Textbox(label="Enter the review ") , outputs=[gr.Textbox(label="sentiment") , gr.Textbox(label="Score")],description='sentiment-analysis')
41
+ summraztion = gr.Interface(fn=summraztion , inputs=gr.Textbox(label="Enter the text ") , outputs=gr.Textbox(label="summraztion") ,description='summraztion')
42
+ chatBot=gr.ChatInterface(chat_bot)
43
+
44
+
45
+ demo = gr.TabbedInterface([sentiment_a, summraztion,chatBot,Audio], ["Sentiment Analysis", "Summraztion","ChatBot",'Audio'])
46
+
47
+ demo.launch(debug=True)