Spaces:
Sleeping
Sleeping
donadelicc
commited on
Commit
•
ee64c2d
1
Parent(s):
001f52b
siste
Browse files- app.py +18 -2
- requirements.txt +2 -1
- test.py +22 -0
app.py
CHANGED
@@ -3,6 +3,8 @@ from fastai.text.all import load_learner
|
|
3 |
import os
|
4 |
import pathlib
|
5 |
|
|
|
|
|
6 |
## Workaround for Windows Path - PathPosix issue
|
7 |
temp = pathlib.PosixPath
|
8 |
pathlib.PosixPath = pathlib.WindowsPath
|
@@ -12,7 +14,21 @@ def predict(text):
|
|
12 |
model_path = "models/LikeItOrNot-base-v1.pkl"
|
13 |
learner = load_learner(model_path)
|
14 |
prediction = learner.predict(text)
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
iface = gr.Interface(fn=predict, inputs="text", outputs="label")
|
18 |
iface.launch()
|
|
|
3 |
import os
|
4 |
import pathlib
|
5 |
|
6 |
+
import torch
|
7 |
+
|
8 |
## Workaround for Windows Path - PathPosix issue
|
9 |
temp = pathlib.PosixPath
|
10 |
pathlib.PosixPath = pathlib.WindowsPath
|
|
|
14 |
model_path = "models/LikeItOrNot-base-v1.pkl"
|
15 |
learner = load_learner(model_path)
|
16 |
prediction = learner.predict(text)
|
17 |
+
|
18 |
+
confidence_score = torch.tensor(prediction[2]).max()
|
19 |
+
confidence= f"{confidence_score:.2%}"
|
20 |
+
|
21 |
+
if str(prediction[0]) == "1":
|
22 |
+
label = "negative"
|
23 |
+
elif str(prediction[0]) == "2":
|
24 |
+
label = "positive"
|
25 |
+
else:
|
26 |
+
label = "dunno"
|
27 |
+
|
28 |
+
output = f"Prediction: {label} and Confidence: {confidence}"
|
29 |
+
|
30 |
+
print(prediction)
|
31 |
+
return output, confidence
|
32 |
|
33 |
+
iface = gr.Interface(fn=predict, inputs="text", outputs=["label", "text"])
|
34 |
iface.launch()
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
gradio
|
2 |
-
fastai
|
|
|
|
1 |
gradio
|
2 |
+
fastai
|
3 |
+
torch
|
test.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.text.all import load_learner
|
2 |
+
import pathlib
|
3 |
+
|
4 |
+
temp = pathlib.PosixPath
|
5 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
6 |
+
|
7 |
+
model_path = "models/LikeItOrNot-base-v1.pkl"
|
8 |
+
learner = load_learner(model_path)
|
9 |
+
text = "I love this movie!"
|
10 |
+
prediction = learner.predict(text)
|
11 |
+
if str(prediction[0]) == "1":
|
12 |
+
print("negative")
|
13 |
+
elif str(prediction[0]) == "2":
|
14 |
+
print("positive")
|
15 |
+
else:
|
16 |
+
print("dunno")
|
17 |
+
|
18 |
+
print("------")
|
19 |
+
print(prediction[0])
|
20 |
+
print(type(prediction[0]))
|
21 |
+
print("------")
|
22 |
+
print(prediction)
|