import tensorflow as tf from transformers import pipeline import gradio as gr # importing necessary libraries from transformers import AutoTokenizer, TFAutoModelForQuestionAnswering tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad") model = TFAutoModelForQuestionAnswering.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad",return_dict=False) nlp = pipeline("question-answering", model=model, tokenizer=tokenizer) context = "My name is Hema Raikhola, i am a data scientist and machine learning engineer.मेरो नाम हेमा हो। म नेपालीमा बोल्न जान्दछु। मशीन लर्निंग आर्टिफिशियल इंटेलिजेंस की एक शाखा है। यह एक लोकप्रिय प्रमुख है।" question = "what is my profession?" result = nlp(question = question, context=context) print(f"QUESTION: {question}") print(f"ANSWER: {result['answer']}") # creating the function def func(context, question): result = nlp(question = question, context=context) return result['answer'] example_1 ="Linear regression is one of the easiest and most popular Machine Learning algorithms. It is a statistical method that is used for predictive analysis. Linear regression makes predictions for continuous/real or numeric variables such as sales, salary, age, product price, etc." qst_1 = "What is Linear Regression?" example_2 = "(2) Natural Language Processing (NLP) allows machines to break down and interpret human language. It's at the core of tools we use every day – from translation software, chatbots, spam filters, and search engines, to grammar correction software, voice assistants, and social media monitoring tools." qst_2 = "What is NLP used for?" example_3 = "(3) मशीन लर्निंग आर्टिफिशियल इंटेलिजेंस की एक शाखा है। यह एक लोकप्रिय प्रमुख है।" qst_3 = "मशीन लर्निंग किसकी एक शाखा है?" example_4 = "(4) माउन्ट एवरेस्ट विश्वको सबैभन्दा अग्लो हिमाल हो, जसको शिखर समुन्द्री सतहबाट 8,848 मिटर(29,029 फिट) उचाइमा छ। यो हिमालयमा नेपाल र तिब्बत (चीन) बीचको सीमामा रहेको महालंगुर पर्वतमालामा अवस्थित छ।" qst_4 ="सगरमाथाको उचाई कति छ ?" # creating the interface app = gr.Interface(fn=func, inputs = ['textbox', 'text'], outputs = gr.Textbox( lines=10), title = 'Question Answering bot', description = 'Input context and question, then get answers!', examples = [[example_1, qst_1], [example_2, qst_2], [example_3, qst_3], [example_4, qst_4]], allow_flagging="manual", ).queue() # launching the app app.launch(auth = ('user','saitmhpsk'), auth_message = "Check your Login details sent to your email")