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