accept multiple articles
Browse files
app.py
CHANGED
@@ -1,10 +1,11 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from nextus_regressor_class import *
|
|
|
4 |
import nltk
|
5 |
from pprint import pprint
|
6 |
import pandas as pd
|
7 |
-
|
8 |
model = NextUsRegressor()
|
9 |
model.load_state_dict(torch.load("./nextus_regressor1012.pt"))
|
10 |
model.eval()
|
@@ -40,26 +41,35 @@ def shap(txt, tok_level):
|
|
40 |
# labels = ["+" if s < -1.0*threshold "-" elif s > threshold else " " for s in shapss]
|
41 |
# print(len(tokens), len(labels))
|
42 |
# print(list(zip(tokens, labels)))
|
43 |
-
|
44 |
# return str(list(zip(tokens, labels)))
|
45 |
-
|
|
|
|
|
|
|
46 |
# return txt
|
47 |
|
|
|
48 |
def parse_file_input(f):
|
|
|
49 |
all_articles = list()
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
57 |
scores = model(all_articles)
|
58 |
return scores
|
59 |
|
60 |
demo = gr.Interface(parse_file_input,
|
61 |
[
|
62 |
-
gr.File(file_count="single", file_types=[".csv", ".xls", ".xlsx"], label="๊ธฐ์ฌ ํ์ผ(csv/excel)์ ์
๋ก๋ํ์ธ์")
|
63 |
#gr.Textbox(label="๊ธฐ์ฌ", lines=30, placeholder="๊ธฐ์ฌ๋ฅผ ์
๋ ฅํ์ธ์."),
|
64 |
# gr.Radio(choices=["sentence", "word"], label="ํด์ค ํ์ ๋จ์", value="sentence", info="๋ฌธ์ฅ ๋จ์์ ํด์ค์ sentence๋ฅผ, ๋จ์ด ๋จ์์ ํด์ค์ word๋ฅผ ์ ํํ์ธ์.")
|
65 |
],
|
|
|
1 |
+
import io
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
+
# from nextus_regressor_class import *
|
5 |
+
from nextus_regressor_class1027 import *
|
6 |
import nltk
|
7 |
from pprint import pprint
|
8 |
import pandas as pd
|
|
|
9 |
model = NextUsRegressor()
|
10 |
model.load_state_dict(torch.load("./nextus_regressor1012.pt"))
|
11 |
model.eval()
|
|
|
41 |
# labels = ["+" if s < -1.0*threshold "-" elif s > threshold else " " for s in shapss]
|
42 |
# print(len(tokens), len(labels))
|
43 |
# print(list(zip(tokens, labels)))
|
44 |
+
pprint(list(zip(tokens, shapss)))
|
45 |
# return str(list(zip(tokens, labels)))
|
46 |
+
largest_shap = torch.max(y_offs - y_pred).item()
|
47 |
+
largest_shap_span = tokens[torch.argmax(y_offs - y_pred).item()]
|
48 |
+
explanation = "๊ฐ์ฅ ํฐ ์ํฅ์ ๋ฏธ์น ํ
์คํธ๋\n'"+ largest_shap_span+ "'\n์ด๋ฉฐ, ํด๋น ํ
์คํธ๊ฐ ์์ ๊ฒฝ์ฐ Slant ์ค์ฝ์ด\n" + str(round(y_pred.item(), 4))+ "\n์์\n"+ str(round(largest_shap,4))+ "\n๋งํผ ๋ฒ์ด๋ฉ๋๋ค."
|
49 |
+
return list(zip(tokens, labels)), explanation
|
50 |
# return txt
|
51 |
|
52 |
+
|
53 |
def parse_file_input(f):
|
54 |
+
# print(f, type(f))
|
55 |
all_articles = list()
|
56 |
+
|
57 |
+
# with open(f, "r") as fh:
|
58 |
+
if ".csv" in f.name:
|
59 |
+
|
60 |
+
all_articles += pd.read_csv(f.name).iloc[:, 0].to_list()
|
61 |
+
elif ".xls" in f.name:
|
62 |
+
all_articles += pd.read_excel(f.name).iloc[:, 0].to_list()
|
63 |
+
else:
|
64 |
+
pass
|
65 |
+
# print(len(all_articles))
|
66 |
+
# print(all_articles)
|
67 |
scores = model(all_articles)
|
68 |
return scores
|
69 |
|
70 |
demo = gr.Interface(parse_file_input,
|
71 |
[
|
72 |
+
gr.File(file_count="single", file_types=[".csv", ".xls", ".xlsx"], type="file", label="๊ธฐ์ฌ ํ์ผ(csv/excel)์ ์
๋ก๋ํ์ธ์")
|
73 |
#gr.Textbox(label="๊ธฐ์ฌ", lines=30, placeholder="๊ธฐ์ฌ๋ฅผ ์
๋ ฅํ์ธ์."),
|
74 |
# gr.Radio(choices=["sentence", "word"], label="ํด์ค ํ์ ๋จ์", value="sentence", info="๋ฌธ์ฅ ๋จ์์ ํด์ค์ sentence๋ฅผ, ๋จ์ด ๋จ์์ ํด์ค์ word๋ฅผ ์ ํํ์ธ์.")
|
75 |
],
|