Spaces:
Runtime error
Runtime error
Truong-Phuc Nguyen
commited on
Commit
•
8bf4c24
1
Parent(s):
d6acde9
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,28 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import torch
|
3 |
-
from transformers import pipeline
|
4 |
-
|
5 |
-
st.set_page_config(page_title="Vietnamese Legal Question Answering", page_icon="🧊", layout="
|
6 |
-
|
7 |
-
@st.cache_data
|
8 |
-
def load_model(model_path):
|
9 |
-
device = 0 if torch.cuda.is_available() else -1
|
10 |
-
question_answerer = pipeline("question-answering", model=model_path, device=device)
|
11 |
-
return question_answerer
|
12 |
-
|
13 |
-
def get_answer(model, context, question):
|
14 |
-
return model(context=context, question=question, max_answer_len=512)
|
15 |
-
|
16 |
-
if 'model' not in st.session_state:
|
17 |
-
st.session_state.model = load_model(model_path='./
|
18 |
-
|
19 |
-
st.markdown("<h1 style='text-align: center;'>Vietnamese Legal Question Answering</h1>", unsafe_allow_html=True)
|
20 |
-
|
21 |
-
context = st.text_area(label='Vietnamese Legal Documents/context:', placeholder='Enter your Vietnamese legal document here...', height=300)
|
22 |
-
question = st.text_area(label='Question about this Vietnamese Legal Documents:', placeholder='Enter your question about this Vietnamese Legal Documents here...', height=100)
|
23 |
-
|
24 |
-
btn_answer = st.button(label='Answer')
|
25 |
-
|
26 |
-
if btn_answer:
|
27 |
-
answer = get_answer(model=st.session_state.model, context=context, question=question)
|
28 |
-
st.success(f"{answer['answer']}")
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
st.set_page_config(page_title="Vietnamese Legal Question Answering", page_icon="🧊", layout="wide", initial_sidebar_state="collapsed")
|
6 |
+
|
7 |
+
@st.cache_data
|
8 |
+
def load_model(model_path):
|
9 |
+
device = 0 if torch.cuda.is_available() else -1
|
10 |
+
question_answerer = pipeline("question-answering", model=model_path, device=device)
|
11 |
+
return question_answerer
|
12 |
+
|
13 |
+
def get_answer(model, context, question):
|
14 |
+
return model(context=context, question=question, max_answer_len=512)
|
15 |
+
|
16 |
+
if 'model' not in st.session_state:
|
17 |
+
st.session_state.model = load_model(model_path='./model')
|
18 |
+
|
19 |
+
st.markdown("<h1 style='text-align: center;'>Vietnamese Legal Question Answering</h1>", unsafe_allow_html=True)
|
20 |
+
|
21 |
+
context = st.text_area(label='Vietnamese Legal Documents/context:', placeholder='Enter your Vietnamese legal document here...', height=300)
|
22 |
+
question = st.text_area(label='Question about this Vietnamese Legal Documents:', placeholder='Enter your question about this Vietnamese Legal Documents here...', height=100)
|
23 |
+
|
24 |
+
btn_answer = st.button(label='Answer')
|
25 |
+
|
26 |
+
if btn_answer:
|
27 |
+
answer = get_answer(model=st.session_state.model, context=context, question=question)
|
28 |
+
st.success(f"{answer['answer']}")
|