eyadpy commited on
Commit
db5e8bd
1 Parent(s): 335a0d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -22
app.py CHANGED
@@ -4,13 +4,13 @@ from streamlit_chat import message as st_message
4
  # from transformers import BlenderbotForConditionalGeneration
5
  from transformers import pipeline
6
 
7
- context = '''
8
- نحن شركة متخصصة فى مجال الزكاء الاصطناعى.
9
- نقدم العديد من الخدمات كالحلول للشركات و تدريبات فى مجال الزكاء الاصطناعى.
10
- التدريبات المتاحة الان هى ETE و computer vision.
11
- سعر ال ETE 4500 جنيه مصرى بدلا من 5000 جنيه.
12
- وسعر ال computer vision 6000 جنيه مصرى بدلا من 6500 جنيه مصرى.
13
- '''
14
 
15
 
16
  @st.cache(allow_output_mutation=True)
@@ -19,35 +19,42 @@ def load_model():
19
  return model
20
  qa = load_model()
21
 
 
22
 
23
  if "history" not in st.session_state:
24
  st.session_state.history = []
25
 
26
- st.title('Ask a question about Electro-pi')
27
  # qa = load_model()
28
  # user_message = st.session_state.input_text
29
 
30
 
31
 
32
  def generate_answer():
33
- qa = load_model()
34
  user_message = st.session_state.input_text
35
  # inputs = tokenizer(st.session_state.input_text, return_tensors="pt")
36
  # result = model.generate(**inputs)
37
- message_bot = qa(question= user_message, context= context)
38
- print(message_bot)
39
- if message_bot['score'] <= 0.2:
40
- message_bot = "electrobot: sorry i didn't get that"
41
- st.session_state.history.append({"message": user_message, "is_user": True})
42
- st.session_state.history.append({"message": message_bot, "is_user": False})
43
- else:
44
- st.session_state.history.append({"message": user_message, "is_user": True})
45
- st.session_state.history.append({"message": message_bot['answer'], "is_user": False})
46
-
47
- print('2')
 
 
 
 
48
  st.text_input("Talk to the bot", key="input_text", on_change=generate_answer)
49
  print('3')
50
  for chat in st.session_state.history:
51
  # print('4')
52
- st_message(**chat) # unpacking
53
- print('4')
 
 
 
 
4
  # from transformers import BlenderbotForConditionalGeneration
5
  from transformers import pipeline
6
 
7
+ # context = '''
8
+ # نحن شركة متخصصة فى مجال الزكاء الاصطناعى.
9
+ # نقدم العديد من الخدمات كالحلول للشركات و تدريبات فى مجال الزكاء الاصطناعى.
10
+ # التدريبات المتاحة الان هى ETE و computer vision.
11
+ # سعر ال ETE 4500 جنيه مصرى بدلا من 5000 جنيه.
12
+ # وسعر ال computer vision 6000 جنيه مصرى بدلا من 6500 جنيه مصرى.
13
+ # '''
14
 
15
 
16
  @st.cache(allow_output_mutation=True)
 
19
  return model
20
  qa = load_model()
21
 
22
+ context = st.text_area("please enter your article")
23
 
24
  if "history" not in st.session_state:
25
  st.session_state.history = []
26
 
27
+ # st.title('Ask a question about Electro-pi')
28
  # qa = load_model()
29
  # user_message = st.session_state.input_text
30
 
31
 
32
 
33
  def generate_answer():
 
34
  user_message = st.session_state.input_text
35
  # inputs = tokenizer(st.session_state.input_text, return_tensors="pt")
36
  # result = model.generate(**inputs)
37
+
38
+ try:
39
+ message_bot = qa(question= user_message, context= context)
40
+ print(message_bot)
41
+
42
+ if message_bot['score'] <= 0.2:
43
+ message_bot = "electrobot: sorry i didn't get that"
44
+ st.session_state.history.append({"message": user_message, "is_user": True})
45
+ st.session_state.history.append({"message": message_bot, "is_user": False})
46
+ else:
47
+ st.session_state.history.append({"message": user_message, "is_user": True})
48
+ st.session_state.history.append({"message": message_bot['answer'], "is_user": False})
49
+ except:
50
+ print("Empty")
51
+
52
  st.text_input("Talk to the bot", key="input_text", on_change=generate_answer)
53
  print('3')
54
  for chat in st.session_state.history:
55
  # print('4')
56
+ try:
57
+ st_message(**chat) # unpacking
58
+ except:
59
+ print("ERROR")
60
+ continue