Spaces:
Sleeping
Sleeping
Commit
·
dd1cd76
1
Parent(s):
3047c0d
Update pages/answers.py
Browse files- pages/answers.py +0 -31
pages/answers.py
CHANGED
@@ -50,37 +50,6 @@ def get_answer(context, question):
|
|
50 |
answer = res['answer']
|
51 |
return answer
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
Приношу извинения за неудобства. Кажется, я снова сделал ошибку. Для достижения желаемого поведения необходимо использовать st.sidebar для сохранения и обновления значений переменных context и question. Вот исправленный код:
|
56 |
-
|
57 |
-
python
|
58 |
-
Copy code
|
59 |
-
import random
|
60 |
-
import streamlit as st
|
61 |
-
from transformers import AutoModelForQuestionAnswering, AutoTokenizer, pipeline
|
62 |
-
|
63 |
-
|
64 |
-
model_name = "deepset/roberta-base-squad2"
|
65 |
-
model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
66 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
67 |
-
|
68 |
-
pairs = [
|
69 |
-
{
|
70 |
-
'context': "In recent years, climate change has become a pressing global issue. Rising temperatures, melting ice caps, and extreme weather events are all indicators of the changing climate. Governments around the world are implementing measures to reduce carbon emissions and promote renewable energy sources. The Paris Agreement, signed in 2015, aims to limit global warming to well below 2 degrees Celsius. Despite these efforts, challenges remain in achieving sustainable development while mitigating climate change.",
|
71 |
-
'question': "What are some measures governments are taking to address climate change?"
|
72 |
-
}
|
73 |
-
]
|
74 |
-
|
75 |
-
|
76 |
-
def get_answer(context, question):
|
77 |
-
nlp = pipeline('question-answering', model=model, tokenizer=tokenizer)
|
78 |
-
QA_input = {'question': question, 'context': context}
|
79 |
-
res = nlp(QA_input)
|
80 |
-
answer = res['answer']
|
81 |
-
return answer
|
82 |
-
|
83 |
-
|
84 |
def main():
|
85 |
st.title("Question Answering App :robot_face:")
|
86 |
st.divider()
|
|
|
50 |
answer = res['answer']
|
51 |
return answer
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
def main():
|
54 |
st.title("Question Answering App :robot_face:")
|
55 |
st.divider()
|