Madhana commited on
Commit
fcfe4a2
·
1 Parent(s): 7aae0e6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ summarizer = pipeline(task="summarization", model="t5-small")
5
+ def summarize_text(x,y):
6
+ return summarizer(x,max_length=y)[0]["summary_text"]
7
+
8
+ translator = pipeline(task="translation", model="t5-small")
9
+ def translate_text(x):
10
+ return translator(x)[0]["translation_text"]
11
+
12
+ classifier = pipeline(task="sentiment-analysis")
13
+ def text_classification(x):
14
+ preds = classifier(x)
15
+ return [pred["label"] for pred in preds]
16
+
17
+ demo = gr.Blocks()
18
+
19
+ with demo:
20
+ gr.Markdown("Language Modeling Tasks")
21
+ with gr.Tabs():
22
+ with gr.TabItem("Text Classification"):
23
+ with gr.Row():
24
+ tc_input = gr.Textbox(label = "Input Text")
25
+ tc_output = gr.Textbox(label = "Output")
26
+ tc_button = gr.Button("Classify")
27
+ with gr.TabItem("Summarization"):
28
+ with gr.Row():
29
+ s_input = gr.Textbox(label = "Input Text")
30
+ s_output = gr.Textbox(label = "Output Text")
31
+ s_button = gr.Button("Summarize")
32
+ with gr.TabItem("Translator"):
33
+ with gr.Row():
34
+ translate_input = gr.Textbox(label = "Input Text")
35
+ translate_output = gr.Textbox(label = "Output Text")
36
+ translate_button = gr.Button("Translate")
37
+
38
+ tc_button.click(text_classification, inputs=tc_input, outputs=tc_output)
39
+ s_button.click(summarize_text, inputs=s_input, outputs=s_output)
40
+ translate_button.click(translate_text, inputs=translate_input, outputs=translate_output)
41
+
42
+
43
+ demo.launch(share=True)