Spaces:
Sleeping
Sleeping
Annaamalai
commited on
Commit
•
ff1bd0f
1
Parent(s):
1ab3e78
Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,37 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
|
4 |
-
# Load the
|
5 |
-
model_name = "
|
6 |
-
|
7 |
-
|
8 |
|
9 |
# Streamlit app
|
10 |
def main():
|
11 |
-
st.title("
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
st.write(
|
35 |
-
st.write(generated_text)
|
36 |
|
37 |
if __name__ == "__main__":
|
38 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import BigBirdForQuestionAnswering, BigBirdTokenizer
|
3 |
|
4 |
+
# Load the BigBird model and tokenizer
|
5 |
+
model_name = "google/bigbird-base-trivia-itc"
|
6 |
+
model = BigBirdForQuestionAnswering.from_pretrained(model_name)
|
7 |
+
tokenizer = BigBirdTokenizer.from_pretrained(model_name)
|
8 |
|
9 |
# Streamlit app
|
10 |
def main():
|
11 |
+
st.title("CherryBot")
|
12 |
+
|
13 |
+
# Text input for user to input the question
|
14 |
+
question = st.text_input("Enter your question:")
|
15 |
+
|
16 |
+
# Text area for user to input the context
|
17 |
+
context = st.text_area("Enter the context for answering:", height=200)
|
18 |
+
|
19 |
+
# Perform question answering when the user clicks the button
|
20 |
+
if st.button("Get Answer"):
|
21 |
+
if question and context:
|
22 |
+
# Tokenize input question and context
|
23 |
+
encoded_input = tokenizer(question, context, return_tensors='pt')
|
24 |
+
|
25 |
+
# Perform question answering using the loaded model
|
26 |
+
output = model(**encoded_input)
|
27 |
+
|
28 |
+
# Extract and display the answer
|
29 |
+
answer_start = output.start_logits.argmax()
|
30 |
+
answer_end = output.end_logits.argmax() + 1
|
31 |
+
answer = tokenizer.convert_tokens_to_string(tokenizer.convert_ids_to_tokens(encoded_input.input_ids[0][answer_start:answer_end]))
|
32 |
+
|
33 |
+
st.write("Answer:")
|
34 |
+
st.write(answer)
|
|
|
35 |
|
36 |
if __name__ == "__main__":
|
37 |
main()
|