Spaces:
Runtime error
Runtime error
nguyennghia0902
commited on
Commit
•
731e929
1
Parent(s):
993f231
Update Information_Retrieval.py
Browse files- Information_Retrieval.py +32 -12
Information_Retrieval.py
CHANGED
@@ -13,7 +13,7 @@ from pyvi import ViTokenizer
|
|
13 |
@st.cache_resource
|
14 |
def open2list_vn(path):
|
15 |
if path:
|
16 |
-
with open(path) as f:
|
17 |
line = list(f.read().splitlines())
|
18 |
return line
|
19 |
def pre_progress(input):
|
@@ -60,31 +60,51 @@ def main():
|
|
60 |
st.set_page_config(page_title="Information Retrieval", page_icon="📝")
|
61 |
|
62 |
# giving a title to our page
|
63 |
-
st.
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
)
|
69 |
question = st.text_area(
|
70 |
-
"Please enter a question:",
|
71 |
placeholder="Enter your question here",
|
72 |
-
height=
|
|
|
|
|
|
|
|
|
|
|
73 |
)
|
74 |
|
75 |
prediction = ""
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
# Create a prediction button
|
78 |
-
|
|
|
79 |
stripped = text.strip()
|
80 |
if not stripped:
|
81 |
-
st.error("Please enter
|
82 |
return
|
83 |
stripped = question.strip()
|
84 |
if not stripped:
|
85 |
st.error("Please enter a question.")
|
86 |
return
|
87 |
-
|
88 |
prediction = predict(question, text)
|
89 |
if prediction == "TRUE":
|
90 |
st.success("TRUE 😄")
|
|
|
13 |
@st.cache_resource
|
14 |
def open2list_vn(path):
|
15 |
if path:
|
16 |
+
with open(path, encoding="utf8") as f:
|
17 |
line = list(f.read().splitlines())
|
18 |
return line
|
19 |
def pre_progress(input):
|
|
|
60 |
st.set_page_config(page_title="Information Retrieval", page_icon="📝")
|
61 |
|
62 |
# giving a title to our page
|
63 |
+
col1, col2 = st.columns([2, 1])
|
64 |
+
col1.title("Information Retrieval")
|
65 |
+
|
66 |
+
col2.link_button("Explore my model", "https://huggingface.co/nguyennghia0902/textming_proj01_electra")
|
67 |
+
|
|
|
68 |
question = st.text_area(
|
69 |
+
"QUESTION: Please enter a question:",
|
70 |
placeholder="Enter your question here",
|
71 |
+
height=15,
|
72 |
+
)
|
73 |
+
text = st.text_area(
|
74 |
+
"CONTEXT: Please enter a context:",
|
75 |
+
placeholder="Enter your context here",
|
76 |
+
height=100,
|
77 |
)
|
78 |
|
79 |
prediction = ""
|
80 |
|
81 |
+
upload_file = st.file_uploader("CONTEXT: Or upload a file with some contexts", type=["txt"])
|
82 |
+
if upload_file is not None:
|
83 |
+
text = upload_file.read().decode("utf-8")
|
84 |
+
|
85 |
+
for line in text.splitlines():
|
86 |
+
line = line.strip()
|
87 |
+
if not line:
|
88 |
+
continue
|
89 |
+
|
90 |
+
prediction = predict(question, line)
|
91 |
+
if prediction == "TRUE":
|
92 |
+
st.success(line + "\n\nTRUE 😄")
|
93 |
+
else:
|
94 |
+
st.warning(line + "\n\nFALSE 😟")
|
95 |
+
|
96 |
# Create a prediction button
|
97 |
+
elif st.button("Predict"):
|
98 |
+
prediction = ""
|
99 |
stripped = text.strip()
|
100 |
if not stripped:
|
101 |
+
st.error("Please enter a contextext.")
|
102 |
return
|
103 |
stripped = question.strip()
|
104 |
if not stripped:
|
105 |
st.error("Please enter a question.")
|
106 |
return
|
107 |
+
|
108 |
prediction = predict(question, text)
|
109 |
if prediction == "TRUE":
|
110 |
st.success("TRUE 😄")
|