dwhitena's picture
initial commit
8f6eb0f
raw
history blame
839 Bytes
import os
from laserembeddings import Laser
from scipy import spatial
from transformers import pipeline
import gradio as gr
model = pipeline('question-answering')
os.system("python -m laserembeddings download-models")
laser = Laser()
def question_answer(draft, reference, question):
ref_answer = model({'question': question, 'context': reference})['answer']
draft_answer = model({'question': question, 'context': draft})['answer']
embs = laser.embed_sentences([ref_answer, draft_answer], lang='en')
sim = 1 - spatial.distance.cosine(embs[0], embs[1])
if sim >= 0.8:
out = "🎉 Great draft. No comprehensibility warning."
else:
out = "⚠️ Potential comprehensibility issue!"
return out
iface = gr.Interface(fn=question_answer, inputs=["text", "text", "text"], outputs=["text"]).launch()