alikhantoleberdyev commited on
Commit
83ce241
·
1 Parent(s): ef6a576

build v1.2

Browse files
Files changed (1) hide show
  1. app.py +34 -2
app.py CHANGED
@@ -1,4 +1,36 @@
1
  import streamlit as st
 
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import altair as alt
3
+ from transformers import pipeline
4
+ from transformers import AutoModelForSeq2SeqLM , AutoTokenizer, TranslationPipeline
5
 
6
+
7
+
8
+ st.title('NLP Question Answering 🕵️‍♂️')
9
+ st.write('Ask a question about NLP, and I will answer based on the provided context! 🔄')
10
+ user_input = st.text_area("enter question about NLP", "What is tokenizer?")
11
+ @st.cache_resource
12
+ def load_model():
13
+ print("Loading model...")
14
+ return pipeline("question-answering", model="deepset/roberta-base-squad2")
15
+
16
+
17
+ dunno_answerer = load_model()
18
+ with open('NLP_History_and_Facts.txt', 'r') as file:
19
+ context = file.read()
20
+
21
+ if st.button("Answer!"):
22
+ if user_input.strip():
23
+ # Generate an answer using the model
24
+ result = dunno_answerer(question=user_input, context=context)
25
+
26
+ # Display the answer and additional information
27
+ st.write(f"**Answer:** {result['answer']}")
28
+ st.write(f"**Confidence Score:** {round(result['score'], 4)}")
29
+ st.write(f"**Answer Start Position:** {result['start']}")
30
+ st.write(f"**Answer End Position:** {result['end']}")
31
+ else:
32
+ st.write("Please enter a valid question!")
33
+
34
+ # x = st.slider('Select a value')
35
+ # st.write(x, 'squared is', x * x)
36
+ # print(x)