File size: 813 Bytes
2cf76c1
4085164
f82f0ad
2cf76c1
19f3906
22f340e
19f3906
 
97e366e
2cf76c1
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
import gradio as gr
import torch

nlp = pipeline('question-answering',
               model="databricks/dolly-v2-3b",
               torch_dtype=torch.bfloat16, 
               trust_remote_code=True, 
               device_map="auto")

def qnamodel(context,question):
  question_set = {'context':context,'question':question}
  results = nlp(question_set)
  return results['answer']

interface = gr.Interface(fn=qnamodel, 
                        inputs=[gr.inputs.Textbox(lines=7, label="Context"), gr.inputs.Textbox(lines=2, label="Question")],
                        outputs= gr.outputs.Textbox(label="Answer"),
                        title='Context Question Answering')
                        
interface.launch(inline=False)