Commit
·
a47415e
1
Parent(s):
5888c6a
Initial FastAPI app for answer evaluation
Browse files- .gitattributes +35 -0
- Procfile +0 -1
- README.md +10 -0
- answer_similarity_dataset.xls +0 -101
- app.py +60 -94
- index.html +19 -0
- requirements.txt +9 -9
- style.css +28 -0
- templates/index.html +3 -2
- utils/__pycache__/image_processor.cpython-312.pyc +0 -0
- utils/__pycache__/xlnet_model.cpython-312.pyc +0 -0
- utils/image_processor.py +80 -61
- utils/xlnet_model.py +12 -4
- wsgi.py +0 -4
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
Procfile
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
web: gunicorn wsgi:app
|
|
|
|
README.md
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Answer Evaluation App
|
3 |
+
emoji: 🌍
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: blue
|
6 |
+
sdk: static
|
7 |
+
pinned: false
|
8 |
+
---
|
9 |
+
|
10 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
answer_similarity_dataset.xls
DELETED
@@ -1,101 +0,0 @@
|
|
1 |
-
question,student_answer,reference_answer,score
|
2 |
-
What is the difference between supervised and unsupervised learning?,"data. learning Supervised patterns labeled whereas finds learning hidden uses unlabeled in data, unsupervised","Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.",0.67
|
3 |
-
What is the difference between supervised and unsupervised learning?,"Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.","Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.",0.93
|
4 |
-
What is the difference between supervised and unsupervised learning?,"data, in hidden uses learning unlabeled unsupervised labeled finds patterns learning Supervised data. whereas","Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.",0.65
|
5 |
-
What is the difference between supervised and unsupervised learning?,I think it's about some different concept or not sure.,"Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.",0.07
|
6 |
-
What is the difference between supervised and unsupervised learning?,"Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.","Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.",0.92
|
7 |
-
What is the difference between supervised and unsupervised learning?,"Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.","Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.",0.92
|
8 |
-
What is the difference between supervised and unsupervised learning?,"Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.","Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.",0.89
|
9 |
-
What is the difference between supervised and unsupervised learning?,"Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.","Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.",0.92
|
10 |
-
What is the difference between supervised and unsupervised learning?,"Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.","Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.",0.94
|
11 |
-
What is the difference between supervised and unsupervised learning?,"patterns unsupervised finds Supervised data, unlabeled learning labeled uses hidden learning data. whereas in","Supervised learning uses labeled data, whereas unsupervised learning finds hidden patterns in unlabeled data.",0.74
|
12 |
-
What is overfitting in machine learning?,Overfitting happens when a model performs well on training data but poorly on unseen data.,Overfitting happens when a model performs well on training data but poorly on unseen data.,0.91
|
13 |
-
What is overfitting in machine learning?,a data. model when but well Overfitting unseen on training poorly data on happens performs,Overfitting happens when a model performs well on training data but poorly on unseen data.,0.51
|
14 |
-
What is overfitting in machine learning?,Overfitting happens when a model performs well on training data but poorly on unseen data.,Overfitting happens when a model performs well on training data but poorly on unseen data.,0.87
|
15 |
-
What is overfitting in machine learning?,I think it's about some different concept or not sure.,Overfitting happens when a model performs well on training data but poorly on unseen data.,0.03
|
16 |
-
What is overfitting in machine learning?,unseen data. happens well when Overfitting but data on model on performs training a poorly,Overfitting happens when a model performs well on training data but poorly on unseen data.,0.51
|
17 |
-
What is overfitting in machine learning?,on unseen a performs training when data on happens well but poorly data. Overfitting model,Overfitting happens when a model performs well on training data but poorly on unseen data.,0.74
|
18 |
-
What is overfitting in machine learning?,I think it's about some different concept or not sure.,Overfitting happens when a model performs well on training data but poorly on unseen data.,0.06
|
19 |
-
What is overfitting in machine learning?,Overfitting happens when a model performs well on training data but poorly on unseen data.,Overfitting happens when a model performs well on training data but poorly on unseen data.,0.93
|
20 |
-
What is overfitting in machine learning?,Overfitting happens when a model performs well on training data but poorly on unseen data.,Overfitting happens when a model performs well on training data but poorly on unseen data.,0.86
|
21 |
-
What is overfitting in machine learning?,Overfitting happens when a model performs well on training data but poorly on unseen data.,Overfitting happens when a model performs well on training data but poorly on unseen data.,0.96
|
22 |
-
Explain the use of activation functions in neural networks.,"allowing non-linearity, Activation to networks functions neural model relationships. complex introduce","Activation functions introduce non-linearity, allowing neural networks to model complex relationships.",0.63
|
23 |
-
Explain the use of activation functions in neural networks.,"complex non-linearity, functions relationships. neural introduce allowing Activation to model networks","Activation functions introduce non-linearity, allowing neural networks to model complex relationships.",0.72
|
24 |
-
Explain the use of activation functions in neural networks.,"networks non-linearity, to allowing relationships. complex model introduce Activation functions neural","Activation functions introduce non-linearity, allowing neural networks to model complex relationships.",0.64
|
25 |
-
Explain the use of activation functions in neural networks.,I think it's about some different concept or not sure.,"Activation functions introduce non-linearity, allowing neural networks to model complex relationships.",0.07
|
26 |
-
Explain the use of activation functions in neural networks.,"Activation functions introduce non-linearity, allowing neural networks to model complex relationships.","Activation functions introduce non-linearity, allowing neural networks to model complex relationships.",0.89
|
27 |
-
Explain the use of activation functions in neural networks.,"Activation functions introduce non-linearity, allowing neural networks to model complex relationships.","Activation functions introduce non-linearity, allowing neural networks to model complex relationships.",0.94
|
28 |
-
Explain the use of activation functions in neural networks.,"Activation functions introduce non-linearity, allowing neural networks to model complex relationships.","Activation functions introduce non-linearity, allowing neural networks to model complex relationships.",0.9
|
29 |
-
Explain the use of activation functions in neural networks.,"Activation functions introduce non-linearity, allowing neural networks to model complex relationships.","Activation functions introduce non-linearity, allowing neural networks to model complex relationships.",0.96
|
30 |
-
Explain the use of activation functions in neural networks.,"Activation functions introduce non-linearity, allowing neural networks to model complex relationships.","Activation functions introduce non-linearity, allowing neural networks to model complex relationships.",0.96
|
31 |
-
Explain the use of activation functions in neural networks.,"model neural functions Activation introduce to networks non-linearity, relationships. allowing complex","Activation functions introduce non-linearity, allowing neural networks to model complex relationships.",0.66
|
32 |
-
What are Python decorators?,Python decorators are functions that modify the behavior of another function without changing its code.,Python decorators are functions that modify the behavior of another function without changing its code.,0.96
|
33 |
-
What are Python decorators?,I think it's about some different concept or not sure.,Python decorators are functions that modify the behavior of another function without changing its code.,0.03
|
34 |
-
What are Python decorators?,Python decorators are functions that modify the behavior of another function without changing its code.,Python decorators are functions that modify the behavior of another function without changing its code.,0.94
|
35 |
-
What are Python decorators?,Python decorators are functions that modify the behavior of another function without changing its code.,Python decorators are functions that modify the behavior of another function without changing its code.,0.92
|
36 |
-
What are Python decorators?,behavior function the of without its Python modify another that code. functions changing are decorators,Python decorators are functions that modify the behavior of another function without changing its code.,0.68
|
37 |
-
What are Python decorators?,are of code. without another its Python behavior modify the function changing that decorators functions,Python decorators are functions that modify the behavior of another function without changing its code.,0.61
|
38 |
-
What are Python decorators?,Python decorators are functions that modify the behavior of another function without changing its code.,Python decorators are functions that modify the behavior of another function without changing its code.,0.94
|
39 |
-
What are Python decorators?,another the code. changing are Python without that behavior function functions its of modify decorators,Python decorators are functions that modify the behavior of another function without changing its code.,0.5
|
40 |
-
What are Python decorators?,Python decorators are functions that modify the behavior of another function without changing its code.,Python decorators are functions that modify the behavior of another function without changing its code.,0.88
|
41 |
-
What are Python decorators?,Python decorators are functions that modify the behavior of another function without changing its code.,Python decorators are functions that modify the behavior of another function without changing its code.,0.9
|
42 |
-
How does a convolutional neural network (CNN) work?,learn convolutional to layers CNNs spatial features use images. of hierarchies from automatically,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,0.62
|
43 |
-
How does a convolutional neural network (CNN) work?,I think it's about some different concept or not sure.,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,0.2
|
44 |
-
How does a convolutional neural network (CNN) work?,use spatial to images. CNNs hierarchies convolutional features learn automatically layers of from,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,0.5
|
45 |
-
How does a convolutional neural network (CNN) work?,features spatial use layers learn CNNs of convolutional to from automatically hierarchies images.,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,0.72
|
46 |
-
How does a convolutional neural network (CNN) work?,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,0.93
|
47 |
-
How does a convolutional neural network (CNN) work?,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,0.94
|
48 |
-
How does a convolutional neural network (CNN) work?,I think it's about some different concept or not sure.,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,0.22
|
49 |
-
How does a convolutional neural network (CNN) work?,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,0.88
|
50 |
-
How does a convolutional neural network (CNN) work?,I think it's about some different concept or not sure.,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,0.09
|
51 |
-
How does a convolutional neural network (CNN) work?,of images. learn use features layers spatial CNNs automatically convolutional hierarchies to from,CNNs use convolutional layers to automatically learn spatial hierarchies of features from images.,0.59
|
52 |
-
What is the difference between list and tuple in Python?,"Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.","Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.",0.9
|
53 |
-
What is the difference between list and tuple in Python?,"Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.","Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.",0.94
|
54 |
-
What is the difference between list and tuple in Python?,"fixed-size. immutable Lists are and mutable dynamic, are whereas tuples and","Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.",0.64
|
55 |
-
What is the difference between list and tuple in Python?,"whereas dynamic, are and tuples fixed-size. Lists mutable immutable are and","Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.",0.73
|
56 |
-
What is the difference between list and tuple in Python?,"Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.","Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.",0.95
|
57 |
-
What is the difference between list and tuple in Python?,"Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.","Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.",0.92
|
58 |
-
What is the difference between list and tuple in Python?,"Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.","Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.",0.87
|
59 |
-
What is the difference between list and tuple in Python?,"Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.","Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.",0.86
|
60 |
-
What is the difference between list and tuple in Python?,"immutable mutable fixed-size. are whereas Lists dynamic, and and are tuples","Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.",0.65
|
61 |
-
What is the difference between list and tuple in Python?,"dynamic, tuples mutable are fixed-size. and immutable Lists whereas and are","Lists are mutable and dynamic, whereas tuples are immutable and fixed-size.",0.66
|
62 |
-
What is regularization in ML?,I think it's about some different concept or not sure.,Regularization adds a penalty to the loss function to reduce overfitting.,0.15
|
63 |
-
What is regularization in ML?,function to adds the overfitting. to Regularization a loss reduce penalty,Regularization adds a penalty to the loss function to reduce overfitting.,0.72
|
64 |
-
What is regularization in ML?,Regularization adds a penalty to the loss function to reduce overfitting.,Regularization adds a penalty to the loss function to reduce overfitting.,0.96
|
65 |
-
What is regularization in ML?,Regularization adds a penalty to the loss function to reduce overfitting.,Regularization adds a penalty to the loss function to reduce overfitting.,0.85
|
66 |
-
What is regularization in ML?,Regularization adds a penalty to the loss function to reduce overfitting.,Regularization adds a penalty to the loss function to reduce overfitting.,0.93
|
67 |
-
What is regularization in ML?,I think it's about some different concept or not sure.,Regularization adds a penalty to the loss function to reduce overfitting.,0.06
|
68 |
-
What is regularization in ML?,overfitting. to to adds a Regularization the penalty loss function reduce,Regularization adds a penalty to the loss function to reduce overfitting.,0.65
|
69 |
-
What is regularization in ML?,a loss adds overfitting. to Regularization to function the penalty reduce,Regularization adds a penalty to the loss function to reduce overfitting.,0.55
|
70 |
-
What is regularization in ML?,I think it's about some different concept or not sure.,Regularization adds a penalty to the loss function to reduce overfitting.,0.21
|
71 |
-
What is regularization in ML?,Regularization penalty overfitting. adds loss to to reduce the function a,Regularization adds a penalty to the loss function to reduce overfitting.,0.54
|
72 |
-
What is a confusion matrix?,"A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.","A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.",0.86
|
73 |
-
What is a confusion matrix?,"A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.","A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.",0.92
|
74 |
-
What is a confusion matrix?,"false is positives, showing negatives negatives, positives, in A table false a and true confusion true classification. matrix","A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.",0.68
|
75 |
-
What is a confusion matrix?,"classification. true positives, showing and matrix in a positives, false false confusion A table is negatives, true negatives","A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.",0.64
|
76 |
-
What is a confusion matrix?,"a is true false classification. positives, true confusion table false A positives, negatives, negatives matrix and showing in","A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.",0.52
|
77 |
-
What is a confusion matrix?,"A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.","A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.",0.91
|
78 |
-
What is a confusion matrix?,"A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.","A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.",0.93
|
79 |
-
What is a confusion matrix?,"A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.","A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.",0.91
|
80 |
-
What is a confusion matrix?,I think it's about some different concept or not sure.,"A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.",0.24
|
81 |
-
What is a confusion matrix?,"true A false in false positives, is table confusion true negatives, positives, and classification. a matrix negatives showing","A confusion matrix is a table showing true positives, false positives, true negatives, and false negatives in classification.",0.7
|
82 |
-
What is gradient descent?,I think it's about some different concept or not sure.,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,0.28
|
83 |
-
What is gradient descent?,that the descent by weights gradient. an Gradient on is optimization loss updating algorithm minimizes based,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,0.65
|
84 |
-
What is gradient descent?,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,0.89
|
85 |
-
What is gradient descent?,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,0.88
|
86 |
-
What is gradient descent?,on updating an based loss optimization weights that the minimizes by algorithm is descent Gradient gradient.,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,0.67
|
87 |
-
What is gradient descent?,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,0.99
|
88 |
-
What is gradient descent?,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,0.96
|
89 |
-
What is gradient descent?,the by weights updating algorithm gradient. on is minimizes an descent loss optimization based that Gradient,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,0.58
|
90 |
-
What is gradient descent?,the loss descent optimization minimizes based that is algorithm by on gradient. updating an weights Gradient,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,0.74
|
91 |
-
What is gradient descent?,the gradient. on descent by weights optimization is loss that an based updating Gradient minimizes algorithm,Gradient descent is an optimization algorithm that minimizes loss by updating weights based on the gradient.,0.75
|
92 |
-
What is the role of learning rate in optimization?,Learning step weight size training. rate during the in controls updates,Learning rate controls the step size in weight updates during training.,0.55
|
93 |
-
What is the role of learning rate in optimization?,rate controls size the weight during training. step Learning in updates,Learning rate controls the step size in weight updates during training.,0.57
|
94 |
-
What is the role of learning rate in optimization?,the controls rate Learning training. step updates in size during weight,Learning rate controls the step size in weight updates during training.,0.65
|
95 |
-
What is the role of learning rate in optimization?,during weight Learning in the controls updates step rate training. size,Learning rate controls the step size in weight updates during training.,0.65
|
96 |
-
What is the role of learning rate in optimization?,I think it's about some different concept or not sure.,Learning rate controls the step size in weight updates during training.,0.28
|
97 |
-
What is the role of learning rate in optimization?,during controls in the Learning size step weight training. updates rate,Learning rate controls the step size in weight updates during training.,0.55
|
98 |
-
What is the role of learning rate in optimization?,in during the rate controls step size training. updates Learning weight,Learning rate controls the step size in weight updates during training.,0.63
|
99 |
-
What is the role of learning rate in optimization?,I think it's about some different concept or not sure.,Learning rate controls the step size in weight updates during training.,0.11
|
100 |
-
What is the role of learning rate in optimization?,training. size in rate weight Learning during controls updates step the,Learning rate controls the step size in weight updates during training.,0.57
|
101 |
-
What is the role of learning rate in optimization?,during in the Learning step rate controls size updates training. weight,Learning rate controls the step size in weight updates during training.,0.58
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -1,109 +1,75 @@
|
|
1 |
-
from
|
|
|
|
|
|
|
2 |
import os
|
3 |
-
from werkzeug.utils import secure_filename
|
4 |
from utils.image_processor import extract_text_from_image
|
5 |
from utils.xlnet_model import get_similarity_score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max upload
|
10 |
-
app.config['TIMEOUT'] = 300
|
11 |
-
# Ensure upload directory exists
|
12 |
-
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
13 |
|
14 |
-
ALLOWED_EXTENSIONS = {
|
15 |
|
16 |
def allowed_file(filename):
|
17 |
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
18 |
|
19 |
-
@app.
|
20 |
-
def
|
21 |
-
return
|
22 |
|
23 |
-
@app.
|
24 |
-
def evaluate(
|
|
|
|
|
|
|
|
|
|
|
25 |
try:
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
print("Missing files in request")
|
31 |
-
return jsonify({'error': 'All three images are required'}), 400
|
32 |
-
|
33 |
-
question_file = request.files['question']
|
34 |
-
student_answer_file = request.files['student_answer']
|
35 |
-
reference_answer_file = request.files['reference_answer']
|
36 |
-
|
37 |
-
print(f"File names: {question_file.filename}, {student_answer_file.filename}, {reference_answer_file.filename}")
|
38 |
-
|
39 |
-
# Check if files are valid
|
40 |
-
for file in [question_file, student_answer_file, reference_answer_file]:
|
41 |
-
if file.filename == '':
|
42 |
-
print(f"Empty filename detected")
|
43 |
-
return jsonify({'error': 'One or more files not selected'}), 400
|
44 |
if not allowed_file(file.filename):
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
reference_path = os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(reference_answer_file.filename))
|
52 |
-
|
53 |
-
print(f"Saving files to: {question_path}, {student_path}, {reference_path}")
|
54 |
-
|
55 |
-
question_file.save(question_path)
|
56 |
-
student_answer_file.save(student_path)
|
57 |
-
reference_answer_file.save(reference_path)
|
58 |
-
|
59 |
-
print("Files saved successfully")
|
60 |
-
|
61 |
-
# Extract text from images
|
62 |
-
try:
|
63 |
-
print("Extracting text from question image")
|
64 |
-
question_text = extract_text_from_image(question_path)
|
65 |
-
print(f"Question text: {question_text}")
|
66 |
-
|
67 |
-
print("Extracting text from student answer image")
|
68 |
-
student_answer_text = extract_text_from_image(student_path)
|
69 |
-
print(f"Student answer text: {student_answer_text}")
|
70 |
-
|
71 |
-
print("Extracting text from reference answer image")
|
72 |
-
reference_answer_text = extract_text_from_image(reference_path)
|
73 |
-
print(f"Reference answer text: {reference_answer_text}")
|
74 |
-
|
75 |
-
# Get similarity score
|
76 |
-
print("Calculating similarity score")
|
77 |
-
similarity_score = get_similarity_score(question_text, student_answer_text, reference_answer_text)
|
78 |
-
if similarity_score>=75:
|
79 |
-
similarity_score += 20
|
80 |
-
elif similarity_score>=70 and similarity_score<75:
|
81 |
-
similarity_score +=18
|
82 |
-
elif similarity_score<65 and similarity_score>=60:
|
83 |
-
similarity_score +=16
|
84 |
-
else:
|
85 |
-
similarity_score -= 10
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
'success': True,
|
91 |
-
'score': similarity_score,
|
92 |
-
'question_text': question_text,
|
93 |
-
'student_answer_text': student_answer_text,
|
94 |
-
'reference_answer_text': reference_answer_text
|
95 |
-
})
|
96 |
-
except Exception as e:
|
97 |
-
import traceback
|
98 |
-
print(f"Error in text extraction or scoring: {str(e)}")
|
99 |
-
print(traceback.format_exc())
|
100 |
-
return jsonify({'error': str(e)}), 500
|
101 |
-
except Exception as e:
|
102 |
-
import traceback
|
103 |
-
print(f"Unexpected error in evaluate route: {str(e)}")
|
104 |
-
print(traceback.format_exc())
|
105 |
-
return jsonify({'error': str(e)}), 500
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request, UploadFile, File, Form
|
2 |
+
from fastapi.responses import HTMLResponse, FileResponse
|
3 |
+
from fastapi.staticfiles import StaticFiles
|
4 |
+
from fastapi.templating import Jinja2Templates
|
5 |
import os
|
|
|
6 |
from utils.image_processor import extract_text_from_image
|
7 |
from utils.xlnet_model import get_similarity_score
|
8 |
+
from werkzeug.utils import secure_filename
|
9 |
+
import shutil
|
10 |
+
|
11 |
+
app = FastAPI()
|
12 |
+
|
13 |
+
# Static & Templates
|
14 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
15 |
+
templates = Jinja2Templates(directory="templates")
|
16 |
|
17 |
+
UPLOAD_FOLDER = "static/uploads"
|
18 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg"}
|
21 |
|
22 |
def allowed_file(filename):
|
23 |
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
24 |
|
25 |
+
@app.get("/", response_class=HTMLResponse)
|
26 |
+
def serve_home(request: Request):
|
27 |
+
return templates.TemplateResponse("index.html", {"request": request})
|
28 |
|
29 |
+
@app.post("/evaluate")
|
30 |
+
async def evaluate(
|
31 |
+
request: Request,
|
32 |
+
question: UploadFile = File(...),
|
33 |
+
student_answer: UploadFile = File(...),
|
34 |
+
reference_answer: UploadFile = File(...)
|
35 |
+
):
|
36 |
try:
|
37 |
+
files = {"question": question, "student": student_answer, "reference": reference_answer}
|
38 |
+
paths = {}
|
39 |
+
|
40 |
+
for key, file in files.items():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
if not allowed_file(file.filename):
|
42 |
+
return {"error": f"Invalid file type: {file.filename}"}
|
43 |
+
filename = secure_filename(file.filename)
|
44 |
+
file_path = os.path.join(UPLOAD_FOLDER, filename)
|
45 |
+
with open(file_path, "wb") as buffer:
|
46 |
+
shutil.copyfileobj(file.file, buffer)
|
47 |
+
paths[key] = file_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
+
question_text = extract_text_from_image(paths["question"])
|
50 |
+
student_text = extract_text_from_image(paths["student"])
|
51 |
+
reference_text = extract_text_from_image(paths["reference"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
score = get_similarity_score(question_text, student_text, reference_text)
|
54 |
+
if score >= 75:
|
55 |
+
score += 20
|
56 |
+
elif 70 <= score < 75:
|
57 |
+
score += 18
|
58 |
+
elif 60 <= score < 65:
|
59 |
+
score += 16
|
60 |
+
else:
|
61 |
+
score -= 10
|
62 |
|
63 |
+
return {
|
64 |
+
"success": True,
|
65 |
+
"score": score,
|
66 |
+
"question_text": question_text,
|
67 |
+
"student_answer_text": student_text,
|
68 |
+
"reference_answer_text": reference_text
|
69 |
+
}
|
70 |
+
|
71 |
+
except Exception as e:
|
72 |
+
return {"error": str(e)}
|
73 |
+
if __name__ == "__main__":
|
74 |
+
import uvicorn
|
75 |
+
uvicorn.run("app:app", host="0.0.0.0", port=7860)
|
index.html
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!doctype html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8" />
|
5 |
+
<meta name="viewport" content="width=device-width" />
|
6 |
+
<title>My static Space</title>
|
7 |
+
<link rel="stylesheet" href="style.css" />
|
8 |
+
</head>
|
9 |
+
<body>
|
10 |
+
<div class="card">
|
11 |
+
<h1>Welcome to your static Space!</h1>
|
12 |
+
<p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
|
13 |
+
<p>
|
14 |
+
Also don't forget to check the
|
15 |
+
<a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
|
16 |
+
</p>
|
17 |
+
</div>
|
18 |
+
</body>
|
19 |
+
</html>
|
requirements.txt
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
5 |
pillow
|
6 |
-
transformers
|
7 |
torch
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
jinja2
|
4 |
+
python-multipart
|
5 |
+
werkzeug
|
6 |
pillow
|
|
|
7 |
torch
|
8 |
+
transformers
|
9 |
+
opencv-python
|
10 |
+
easyocr
|
11 |
+
huggingface_hub
|
style.css
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body {
|
2 |
+
padding: 2rem;
|
3 |
+
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
4 |
+
}
|
5 |
+
|
6 |
+
h1 {
|
7 |
+
font-size: 16px;
|
8 |
+
margin-top: 0;
|
9 |
+
}
|
10 |
+
|
11 |
+
p {
|
12 |
+
color: rgb(107, 114, 128);
|
13 |
+
font-size: 15px;
|
14 |
+
margin-bottom: 10px;
|
15 |
+
margin-top: 5px;
|
16 |
+
}
|
17 |
+
|
18 |
+
.card {
|
19 |
+
max-width: 620px;
|
20 |
+
margin: 0 auto;
|
21 |
+
padding: 16px;
|
22 |
+
border: 1px solid lightgray;
|
23 |
+
border-radius: 16px;
|
24 |
+
}
|
25 |
+
|
26 |
+
.card p:last-child {
|
27 |
+
margin-bottom: 0;
|
28 |
+
}
|
templates/index.html
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>Answer Evaluation System</title>
|
7 |
-
<link rel="stylesheet" href="{{ url_for('static',
|
8 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
9 |
</head>
|
10 |
<body>
|
@@ -133,6 +133,7 @@
|
|
133 |
<p>Guided By: A. L. Lavanya, Assistant Professor, CSE, SRKREC.</p>
|
134 |
</footer>
|
135 |
|
136 |
-
<script src="{{ url_for('static',
|
|
|
137 |
</body>
|
138 |
</html>
|
|
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>Answer Evaluation System</title>
|
7 |
+
<link rel="stylesheet" href="{{ request.url_for('static', path='css/style.css') }}">
|
8 |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
|
9 |
</head>
|
10 |
<body>
|
|
|
133 |
<p>Guided By: A. L. Lavanya, Assistant Professor, CSE, SRKREC.</p>
|
134 |
</footer>
|
135 |
|
136 |
+
<script src="{{ request.url_for('static', path='js/main.js') }}"></script>
|
137 |
+
|
138 |
</body>
|
139 |
</html>
|
utils/__pycache__/image_processor.cpython-312.pyc
CHANGED
Binary files a/utils/__pycache__/image_processor.cpython-312.pyc and b/utils/__pycache__/image_processor.cpython-312.pyc differ
|
|
utils/__pycache__/xlnet_model.cpython-312.pyc
CHANGED
Binary files a/utils/__pycache__/xlnet_model.cpython-312.pyc and b/utils/__pycache__/xlnet_model.cpython-312.pyc differ
|
|
utils/image_processor.py
CHANGED
@@ -1,83 +1,102 @@
|
|
|
|
1 |
import cv2
|
|
|
|
|
2 |
import numpy as np
|
3 |
-
|
|
|
4 |
import easyocr
|
5 |
-
from PIL import Image
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
try:
|
10 |
reader = easyocr.Reader(['en'])
|
11 |
-
|
12 |
except Exception as e:
|
13 |
-
print(f"
|
14 |
-
|
15 |
-
ocr_available = False
|
16 |
|
|
|
17 |
def preprocess_image(image):
|
18 |
-
"""
|
19 |
-
Preprocess image to improve OCR accuracy
|
20 |
-
"""
|
21 |
-
# Convert to grayscale if image is color
|
22 |
if len(image.shape) == 3:
|
23 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
24 |
else:
|
25 |
gray = image
|
26 |
-
|
27 |
-
# Apply denoising (less aggressive)
|
28 |
denoised = cv2.fastNlMeansDenoising(gray, h=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
)
|
35 |
|
36 |
-
return
|
37 |
|
|
|
38 |
def extract_text_from_image(image_path):
|
39 |
"""
|
40 |
-
|
41 |
"""
|
42 |
try:
|
43 |
-
if
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
temp_path = os.path.join(os.path.dirname(image_path), f"temp_processed_{os.path.basename(image_path)}")
|
57 |
-
cv2.imwrite(temp_path, processed_image)
|
58 |
-
|
59 |
-
# Extract text using EasyOCR
|
60 |
-
results = reader.readtext(temp_path)
|
61 |
-
|
62 |
-
# Delete temporary file
|
63 |
-
try:
|
64 |
-
os.remove(temp_path)
|
65 |
-
except:
|
66 |
-
pass
|
67 |
-
|
68 |
-
# Combine all detected text
|
69 |
-
text = ' '.join([result[1] for result in results])
|
70 |
-
text = text.strip()
|
71 |
-
|
72 |
-
# If text is empty, try with the original image
|
73 |
-
if not text:
|
74 |
-
results = reader.readtext(image_path)
|
75 |
-
text = ' '.join([result[1] for result in results])
|
76 |
-
text = text.strip()
|
77 |
-
|
78 |
-
return text
|
79 |
-
|
80 |
except Exception as e:
|
81 |
-
print(f"OCR failed: {
|
82 |
-
|
83 |
-
return "Text extraction failed. Please enter text manually."
|
|
|
1 |
+
import os
|
2 |
import cv2
|
3 |
+
import torch
|
4 |
+
from PIL import Image
|
5 |
import numpy as np
|
6 |
+
|
7 |
+
# EasyOCR
|
8 |
import easyocr
|
|
|
9 |
|
10 |
+
# TrOCR (Transformer-based OCR from Hugging Face)
|
11 |
+
from transformers import TrOCRProcessor, VisionEncoderDecoderModel
|
12 |
+
|
13 |
+
# --- Load TrOCR model and processor once ---
|
14 |
+
try:
|
15 |
+
processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
|
16 |
+
trocr_model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
|
17 |
+
trocr_model.eval()
|
18 |
+
use_trocr = True
|
19 |
+
except Exception as e:
|
20 |
+
print(f"TrOCR load failed: {e}")
|
21 |
+
use_trocr = False
|
22 |
+
|
23 |
+
# --- Load EasyOCR once ---
|
24 |
try:
|
25 |
reader = easyocr.Reader(['en'])
|
26 |
+
use_easyocr = True
|
27 |
except Exception as e:
|
28 |
+
print(f"EasyOCR load failed: {e}")
|
29 |
+
use_easyocr = False
|
|
|
30 |
|
31 |
+
# --- Preprocess image for EasyOCR ---
|
32 |
def preprocess_image(image):
|
|
|
|
|
|
|
|
|
33 |
if len(image.shape) == 3:
|
34 |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
35 |
else:
|
36 |
gray = image
|
37 |
+
|
|
|
38 |
denoised = cv2.fastNlMeansDenoising(gray, h=10)
|
39 |
+
processed = cv2.adaptiveThreshold(denoised, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
|
40 |
+
cv2.THRESH_BINARY, 11, 2)
|
41 |
+
return processed
|
42 |
+
|
43 |
+
# --- Preprocess image for TrOCR ---
|
44 |
+
def preprocess_for_trocr(image_path):
|
45 |
+
image = cv2.imread(image_path)
|
46 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
47 |
+
image = cv2.resize(image, (1280, 720), interpolation=cv2.INTER_LINEAR)
|
48 |
+
return Image.fromarray(image)
|
49 |
+
|
50 |
+
# --- TrOCR extraction ---
|
51 |
+
def extract_text_with_trocr(image_path):
|
52 |
+
image = preprocess_for_trocr(image_path)
|
53 |
+
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
54 |
+
|
55 |
+
with torch.no_grad():
|
56 |
+
generated_ids = trocr_model.generate(pixel_values)
|
57 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
58 |
+
|
59 |
+
return generated_text.strip()
|
60 |
+
|
61 |
+
# --- EasyOCR extraction ---
|
62 |
+
def extract_text_with_easyocr(image_path):
|
63 |
+
image = cv2.imread(image_path)
|
64 |
+
processed_image = preprocess_image(image)
|
65 |
+
|
66 |
+
# Use processed image
|
67 |
+
temp_path = os.path.join(os.path.dirname(image_path), f"temp_{os.path.basename(image_path)}")
|
68 |
+
cv2.imwrite(temp_path, processed_image)
|
69 |
+
results = reader.readtext(temp_path)
|
70 |
+
os.remove(temp_path)
|
71 |
+
|
72 |
+
text = ' '.join([res[1] for res in results]).strip()
|
73 |
|
74 |
+
# Fallback to original if empty
|
75 |
+
if not text:
|
76 |
+
results = reader.readtext(image_path)
|
77 |
+
text = ' '.join([res[1] for res in results]).strip()
|
|
|
78 |
|
79 |
+
return text
|
80 |
|
81 |
+
# --- Main unified function ---
|
82 |
def extract_text_from_image(image_path):
|
83 |
"""
|
84 |
+
Try extracting handwritten text using TrOCR. Fallback to EasyOCR.
|
85 |
"""
|
86 |
try:
|
87 |
+
if use_trocr:
|
88 |
+
print("Using TrOCR...")
|
89 |
+
trocr_text = extract_text_with_trocr(image_path)
|
90 |
+
if trocr_text and len(trocr_text.strip()) > 5:
|
91 |
+
return trocr_text
|
92 |
+
print("TrOCR output too short. Falling back to EasyOCR...")
|
93 |
+
|
94 |
+
if use_easyocr:
|
95 |
+
print("Using EasyOCR...")
|
96 |
+
return extract_text_with_easyocr(image_path)
|
97 |
+
|
98 |
+
raise Exception("No OCR backend available.")
|
99 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
except Exception as e:
|
101 |
+
print(f"OCR failed: {e}")
|
102 |
+
return "Text extraction failed."
|
|
utils/xlnet_model.py
CHANGED
@@ -5,9 +5,17 @@ from sklearn.feature_extraction.text import TfidfVectorizer
|
|
5 |
from sklearn.metrics.pairwise import cosine_similarity
|
6 |
|
7 |
# ------------------------------------------------------------------
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def download_model_if_needed():
|
13 |
if os.path.exists(MODEL_PATH):
|
@@ -79,4 +87,4 @@ def get_similarity_score(q, s, r):
|
|
79 |
try:
|
80 |
return get_model_prediction(q, s, r) if xlnet_available else tfidf_similarity(s, r)
|
81 |
except Exception:
|
82 |
-
return fallback_similarity(s, r)
|
|
|
5 |
from sklearn.metrics.pairwise import cosine_similarity
|
6 |
|
7 |
# ------------------------------------------------------------------
|
8 |
+
from huggingface_hub import hf_hub_download
|
9 |
+
import torch
|
10 |
+
|
11 |
+
# Downloads the file automatically from your model repo
|
12 |
+
MODEL_PATH = hf_hub_download(
|
13 |
+
repo_id="yeswanthvarma/xlnet-evaluator-model",
|
14 |
+
filename="xlnet_answer_assessment_model.pt"
|
15 |
+
)
|
16 |
+
|
17 |
+
# Load the model
|
18 |
+
model.load_state_dict(torch.load(MODEL_PATH, map_location=torch.device("cpu")))
|
19 |
|
20 |
def download_model_if_needed():
|
21 |
if os.path.exists(MODEL_PATH):
|
|
|
87 |
try:
|
88 |
return get_model_prediction(q, s, r) if xlnet_available else tfidf_similarity(s, r)
|
89 |
except Exception:
|
90 |
+
return fallback_similarity(s, r)
|
wsgi.py
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
from app import app
|
2 |
-
|
3 |
-
if __name__ == "__main__":
|
4 |
-
app.run()
|
|
|
|
|
|
|
|
|
|