Spaces:
Runtime error
Runtime error
initial commit
Browse files- app.py +24 -0
- requirements.txt +7 -0
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
from laserembeddings import Laser
|
4 |
+
from scipy import spatial
|
5 |
+
from transformers import pipeline
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
model = pipeline('question-answering')
|
9 |
+
os.system("python -m laserembeddings download-models")
|
10 |
+
laser = Laser()
|
11 |
+
|
12 |
+
def question_answer(draft, reference, question):
|
13 |
+
ref_answer = model({'question': question, 'context': reference})['answer']
|
14 |
+
draft_answer = model({'question': question, 'context': draft})['answer']
|
15 |
+
embs = laser.embed_sentences([ref_answer, draft_answer], lang='en')
|
16 |
+
sim = 1 - spatial.distance.cosine(embs[0], embs[1])
|
17 |
+
if sim >= 0.8:
|
18 |
+
out = "🎉 Great draft. No comprehensibility warning."
|
19 |
+
else:
|
20 |
+
out = "⚠️ Potential comprehensibility issue!"
|
21 |
+
return out
|
22 |
+
|
23 |
+
iface = gr.Interface(fn=question_answer, inputs=["text", "text", "text"], outputs=["text"]).launch()
|
24 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|
3 |
+
scipy
|
4 |
+
numpy
|
5 |
+
laserembeddings
|
6 |
+
gradio
|
7 |
+
|