subu4444 commited on
Commit
f52b12a
1 Parent(s): 5bc878f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
3
+ import json
4
+
5
+ context_val = ''
6
+
7
+ q_n_a_model_name = "deepset/roberta-base-squad2"
8
+ q_n_a_model = AutoModelForQuestionAnswering.from_pretrained(q_n_a_model_name)
9
+ tokenizer = AutoTokenizer.from_pretrained(q_n_a_model_name) # Corrected this line
10
+
11
+ context = gr.Textbox(label="Add the Context (Paragraph or texts) for which you want to get insights", lines=10, outputs="text")
12
+
13
+ def q_n_a_fn(context, text):
14
+ QA_input = {'question': text, 'context': context}
15
+ nlp = pipeline('question-answering', model=q_n_a_model, tokenizer=tokenizer)
16
+ res = nlp(QA_input)
17
+ answer = res['answer']
18
+ return answer
19
+
20
+ def classification_fn(text):
21
+ return context
22
+
23
+ def translate_fn(text):
24
+ return context
25
+
26
+ with gr.Blocks(theme='gradio/soft') as demo:
27
+ gr.Markdown("<h1>Basic NLP Operations</h1>")
28
+ gr.Markdown("Bringing basic NLP operations together.")
29
+ with gr.Tab("Question and Answer"):
30
+ with gr.Row():
31
+ gr.Interface(fn=q_n_a_fn, inputs=[context, gr.Textbox(label="Ask question", lines=1)], outputs="text")
32
+
33
+ with gr.Tab("Classifier"):
34
+ with gr.Row():
35
+ gr.Interface(fn=classification_fn, inputs=[context], outputs="label")
36
+
37
+ with gr.Tab("Translation"):
38
+ with gr.Row():
39
+ gr.Interface(fn=translate_fn, inputs=[gr.Radio(["French", "Hindi", "Spanish"], label="Languages", info="Select language")], outputs="text")
40
+
41
+ with gr.Tab("Summarization"):
42
+ with gr.Row():
43
+ gr.Interface(fn=classification_fn, inputs=[context], outputs="label")
44
+
45
+ with gr.Tab("Text To Speech"):
46
+ with gr.Row():
47
+ gr.Interface(fn=classification_fn, inputs=[context], outputs="audio")
48
+
49
+ with gr.Tab("Text To Text"):
50
+ with gr.Row():
51
+ gr.Interface(fn=classification_fn, inputs=[context], outputs="text")
52
+
53
+ if __name__ == "__main__":
54
+ demo.launch()