Spaces:
Sleeping
Sleeping
Commit
·
5795cc4
1
Parent(s):
72ec1a8
Upload 2 files
Browse files- app.py +30 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#import os
|
| 2 |
+
#os.system("python -m pip install --upgrade pip")
|
| 3 |
+
#os.system("pip uninstall -y gradio")
|
| 4 |
+
#os.system("pip install gradio==3.28.3")
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
from sentence_transformers import SentenceTransformer, util
|
| 8 |
+
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 9 |
+
|
| 10 |
+
def check_similarity(actual_answer, user_answer):
|
| 11 |
+
em_1 = model.encode(actual_answer)
|
| 12 |
+
em_2 = model.encode(user_answer)
|
| 13 |
+
cosine_scores = util.cos_sim(em_1, em_2)
|
| 14 |
+
result = cosine_scores.item()
|
| 15 |
+
result = result * 100
|
| 16 |
+
percentage = "{:.0f}".format(result)
|
| 17 |
+
return percentage
|
| 18 |
+
|
| 19 |
+
input_actual_answer = gr.Textbox()
|
| 20 |
+
input_user_answer = gr.Textbox()
|
| 21 |
+
output_percentage = gr.Textbox()
|
| 22 |
+
|
| 23 |
+
interface = gr.Interface(
|
| 24 |
+
fn=check_similarity,
|
| 25 |
+
inputs=[input_actual_answer, input_user_answer],
|
| 26 |
+
outputs=output_percentage
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
interface.launch()
|
| 30 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
sentence-transformers
|