Spaces:
Runtime error
Runtime error
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() | |