HishamSaad commited on
Commit
ab956bf
·
verified ·
1 Parent(s): 57e5bce

Create Tabs.py

Browse files
Files changed (1) hide show
  1. Tabs.py +43 -0
Tabs.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ return result[0]['summary_text']
17
+
18
+ def chat_bot(text,histroy):
19
+ chat_pip=pipeline('text-generation')
20
+ mes=chat_pip(text)
21
+ return mes[0]['generated_text']
22
+
23
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base.en")
24
+
25
+ def transcribe(audio):
26
+ sr, y = audio
27
+ y = y.astype(np.float32)
28
+ y /= np.max(np.abs(y))
29
+
30
+ return transcriber({"sampling_rate": sr, "raw": y})["text"]
31
+
32
+ Audio = gr.Interface(
33
+ transcribe,
34
+ gr.Audio(sources=["microphone"]),
35
+ "text",
36
+ )
37
+
38
+ hello_world = gr.Interface(fn=get_sentiment , inputs=gr.Textbox(label="Enter the review ") , outputs=[gr.Textbox(label="sentiment") , gr.Textbox(label="Score")],description='sentiment-analysis')
39
+ summraztion = gr.Interface(fn=summraztion , inputs=gr.Textbox(label="Enter the text ") , outputs=gr.Textbox(label="summraztion") ,description='summraztion')
40
+ chatBot=gr.ChatInterface(chat_bot)
41
+
42
+
43
+ gr.TabbedInterface([hello_world, summraztion,chatBot,Audio], ["sentiment-analysis", "summraztion","chatBot",'Audio']).lunch(debug=True)