Spaces:
Runtime error
Runtime error
Lucas Tilford commited on
Commit ·
ff294e0
1
Parent(s): cdbcaf3
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from datasets import load_dataset
|
| 4 |
+
|
| 5 |
+
# Load the UFO dataset from Hugging Face in chunks
|
| 6 |
+
dataset = load_dataset('your_dataset_name', split='train', streaming=True)
|
| 7 |
+
|
| 8 |
+
mdl_name = "deepset/roberta-base-squad2"
|
| 9 |
+
my_pipeline = pipeline('question-answering', model=mdl_name, tokenizer=mdl_name)
|
| 10 |
+
|
| 11 |
+
def answer_question(question):
|
| 12 |
+
# Iterate over chunks of the dataset
|
| 13 |
+
for chunk in dataset:
|
| 14 |
+
# Convert the chunk to a string to use as the context
|
| 15 |
+
context = ' '.join([str(item) for item in chunk])
|
| 16 |
+
response = my_pipeline({'question': question, 'context': context})
|
| 17 |
+
if response['score'] > 0.5: # Adjust this threshold as needed
|
| 18 |
+
return response
|
| 19 |
+
|
| 20 |
+
return "No answer found."
|
| 21 |
+
|
| 22 |
+
gr.Interface(answer_question, inputs="text", outputs="text").launch()
|
| 23 |
+
|