Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,8 @@ import json
|
|
4 |
import streamlit as st
|
5 |
|
6 |
model_name = "distilbert-base-cased"
|
7 |
-
tokenizer = DistilBertTokenizerFast.from_pretrained(model_name)
|
|
|
8 |
|
9 |
def format_response(start_index, end_index, raw_answer):
|
10 |
answer_tokens = tokenizer.convert_tokens_to_string([tokenizer.convert_ids_to_tokens(i)[0] for i in range(start_index, end_index+1)])
|
@@ -27,10 +28,20 @@ def interactive():
|
|
27 |
while query != st.session_state.get('current_query', ''):
|
28 |
if ('current_query' not in st.session_state) or (st.session_state['current_query'] != query):
|
29 |
st.session_state['current_query'] = query
|
30 |
-
st.text_input("Ask me something or type 'quit' to exit:", "", key='my_input'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
4 |
import streamlit as st
|
5 |
|
6 |
model_name = "distilbert-base-cased"
|
7 |
+
tokenizer = DistilBertTokenizerFast.from_pretrained(model_name)
|
8 |
+
model = DistilBertForQuestionAnswering.from_pretrained(model_name)
|
9 |
|
10 |
def format_response(start_index, end_index, raw_answer):
|
11 |
answer_tokens = tokenizer.convert_tokens_to_string([tokenizer.convert_ids_to_tokens(i)[0] for i in range(start_index, end_index+1)])
|
|
|
28 |
while query != st.session_state.get('current_query', ''):
|
29 |
if ('current_query' not in st.session_state) or (st.session_state['current_query'] != query):
|
30 |
st.session_state['current_query'] = query
|
31 |
+
st.text_input("Ask me something or type 'quit' to exit:", "", key='my_input')
|
32 |
+
query = st.session_state.get('current_query', '')
|
33 |
+
if query != 'quit':
|
34 |
+
if len(query) > 0:
|
35 |
+
try:
|
36 |
+
context = "The capital of France is Paris."
|
37 |
+
response = get_answers(query, context)
|
38 |
+
st.write(json.dumps(response))
|
39 |
+
except Exception as e:
|
40 |
+
st.write(f"Error occurred: {str(e)}")
|
41 |
|
42 |
+
if __name__ == "__main__":
|
43 |
+
st.set_page_config(layout="wide")
|
44 |
+
st.title('AI Chatbot Built Using Hugging Face and Streamlit')
|
45 |
+
st.subheader('Welcome to Our Intelligent Conversational Agent!')
|
46 |
+
st.write('Please enter your question below or type "quit" to close the session.')
|
47 |
+
interactive()
|