File size: 880 Bytes
ff294e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
import gradio as gr
from datasets import load_dataset

# Load the UFO dataset from Hugging Face in chunks
dataset = load_dataset('your_dataset_name', split='train', streaming=True)

mdl_name = "deepset/roberta-base-squad2"
my_pipeline = pipeline('question-answering', model=mdl_name, tokenizer=mdl_name)

def answer_question(question):
    # Iterate over chunks of the dataset
    for chunk in dataset:
        # Convert the chunk to a string to use as the context
        context = ' '.join([str(item) for item in chunk])
        response = my_pipeline({'question': question, 'context': context})
        if response['score'] > 0.5:  # Adjust this threshold as needed
            return response

    return "No answer found."

gr.Interface(answer_question, inputs="text", outputs="text").launch()