from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline, AutoModelForQuestionAnswering import gradio as gr import torch title = "🤖AI ChatBot" description = "A State-of-the-Art Large-scale Pretrained Response generation model (DialoGPT)" examples = [["How are you?"]] model = AutoModelForQuestionAnswering.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad",return_dict=False) tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad") nlp = pipeline("question-answering", model=model, tokenizer=tokenizer) # tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large") # model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-large") def func(context, question): result = nlp(question = question, context=context) return result['answer'] app = gr.Interface(fn=func, inputs = ['textbox', 'text'], outputs = 'textbox', title = 'Farm QA Bot', theme = 'dark-grass', description = 'Farm QA Bot') app.launch(inline=False)