eyadpy commited on
Commit
ef5d95d
1 Parent(s): d1059a4

first commit

Browse files
Files changed (2) hide show
  1. app.py +53 -0
  2. requirements.txt +110 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_chat import message as st_message
3
+ # from transformers import BlenderbotTokenizer
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)
17
+ def load_model():
18
+ model = pipeline('question-answering',model='ZeyadAhmed/AraElectra-Arabic-SQuADv2-QA')
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')
requirements.txt ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==4.2.0
2
+ argon2-cffi==21.3.0
3
+ argon2-cffi-bindings==21.2.0
4
+ asttokens==2.0.5
5
+ attrs==22.1.0
6
+ backcall==0.2.0
7
+ beautifulsoup4==4.11.1
8
+ bleach==5.0.1
9
+ blinker==1.5
10
+ cachetools==5.2.0
11
+ cffi==1.15.1
12
+ charset-normalizer==2.1.0
13
+ click==8.1.3
14
+ colorama==0.4.5
15
+ commonmark==0.9.1
16
+ debugpy==1.6.2
17
+ decorator==5.1.1
18
+ defusedxml==0.7.1
19
+ entrypoints==0.4
20
+ executing==0.9.1
21
+ fastjsonschema==2.16.1
22
+ filelock==3.7.1
23
+ gitdb==4.0.9
24
+ GitPython==3.1.27
25
+ huggingface-hub==0.8.1
26
+ idna==3.3
27
+ importlib-metadata==4.12.0
28
+ ipykernel==6.15.1
29
+ ipython==8.4.0
30
+ ipython-genutils==0.2.0
31
+ ipywidgets==7.7.1
32
+ jedi==0.18.1
33
+ Jinja2==3.1.2
34
+ jsonschema==4.9.0
35
+ jupyter==1.0.0
36
+ jupyter-client==7.3.4
37
+ jupyter-console==6.4.4
38
+ jupyter-core==4.11.1
39
+ jupyterlab-pygments==0.2.2
40
+ jupyterlab-widgets==1.1.1
41
+ MarkupSafe==2.1.1
42
+ matplotlib-inline==0.1.3
43
+ mistune==0.8.4
44
+ nbclient==0.6.6
45
+ nbconvert==6.5.0
46
+ nbformat==5.4.0
47
+ nest-asyncio==1.5.5
48
+ notebook==6.4.12
49
+ numpy==1.23.1
50
+ packaging==21.3
51
+ pandas==1.4.3
52
+ pandocfilters==1.5.0
53
+ parso==0.8.3
54
+ pickleshare==0.7.5
55
+ Pillow==9.2.0
56
+ prometheus-client==0.14.1
57
+ prompt-toolkit==3.0.30
58
+ protobuf==3.20.1
59
+ psutil==5.9.1
60
+ pure-eval==0.2.2
61
+ pyarrow==8.0.0
62
+ pycparser==2.21
63
+ pydeck==0.7.1
64
+ Pygments==2.12.0
65
+ Pympler==1.0.1
66
+ pyparsing==3.0.9
67
+ pyrsistent==0.18.1
68
+ python-dateutil==2.8.2
69
+ pytz==2022.1
70
+ pytz-deprecation-shim==0.1.0.post0
71
+ pywin32==304
72
+ pywinpty==2.0.6
73
+ PyYAML==6.0
74
+ pyzmq==23.2.0
75
+ qtconsole==5.3.1
76
+ QtPy==2.1.0
77
+ regex==2022.7.25
78
+ requests==2.28.1
79
+ rich==12.5.1
80
+ semver==2.13.0
81
+ Send2Trash==1.8.0
82
+ six==1.16.0
83
+ smmap==5.0.0
84
+ soupsieve==2.3.2.post1
85
+ stack-data==0.3.0
86
+ streamlit==1.11.1
87
+ streamlit-chat==0.0.2.1
88
+ terminado==0.15.0
89
+ tinycss2==1.1.1
90
+ tokenizers==0.12.1
91
+ toml==0.10.2
92
+ toolz==0.12.0
93
+ torch==1.12.0+cu116
94
+ torchaudio==0.12.0+cu116
95
+ torchvision==0.13.0+cu116
96
+ tornado==6.2
97
+ tqdm==4.64.0
98
+ traitlets==5.3.0
99
+ transformers==4.21.0
100
+ typing_extensions==4.3.0
101
+ tzdata==2022.1
102
+ tzlocal==4.2
103
+ urllib3==1.26.11
104
+ validators==0.20.0
105
+ watchdog==2.1.9
106
+ wcwidth==0.2.5
107
+ webencodings==0.5.1
108
+ widgetsnbextension==3.6.1
109
+ wincertstore==0.2
110
+ zipp==3.8.1