Spaces:
Runtime error
Runtime error
File size: 1,711 Bytes
e99d3a5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# -*- coding: utf-8 -*-
"""Job-coach-testing-site-zeroshot.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/github/vanderbilt-data-science/job-coach-question-answering/blob/111-create-a-gradio-hf-space-to-test-whether-specific-information-is-in-a-coaching-document/job-coach-testing-zeroshot.ipynb
"""
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForQuestionAnswering
from transformers import pipeline
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
question_answerer = pipeline("question-answering", model = "bert-large-uncased-whole-word-masking-finetuned-squad")
def zshot(context, queries):
answered=[]
res=[]
notAnswered=[]
queries=queries.split("?")
queries.pop(-1)
for query in queries:
query.strip()
result = question_answerer(question = query, context=context)
answered.append([query,result['answer']])
for item in answered:
result = ([text, classifier(text, item[0])])
if result[1]['scores'][0] > 0.01:
res.append(item[0] +"? Answer: " + item[1])
else:
notAnswered.append(item[0])
result1=''',
'''.join(res)
result1='''Information Included in the Document:
'''+ result1
result2=''',
'''.join(notAnswered)
result2='''
Information not included in the document, on no clearly stated:
'''+ result2
return result1 + result2
app = gr.Interface(
zshot,
inputs=[
gr.Textbox(label="Context", value=""),
gr.Textbox(label="Queries", value=""),
],
outputs=["text"],
)
app.launch()
"""#### Examples""" |