Hackavist commited on
Commit
f7fce72
1 Parent(s): eafe8b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
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)pled by force, as it can have serious consequences. Instead, we should strive for peaceful resolution through dialogue and diplomacy.
 
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', on_change=update_displayed_query) # pass the name of the function here
 
 
 
 
 
 
 
 
 
31
 
32
- if ('shown_query' not in st.session_state) or (st.session_state['shown_query'] != query):
33
- st.session_state['shown_query'] = query
34
- if len(query) > 0 and query != 'quit':
35
- try:
36
- context
 
 
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()