hassanalsawadi commited on
Commit
8d9a37e
Β·
1 Parent(s): b3ec3ed

Add application file

Browse files
Files changed (5) hide show
  1. Dockerfile +15 -0
  2. README.md +6 -4
  3. absher_user_guide_with_embeddings_1k.csv +0 -0
  4. app.py +93 -0
  5. requirements.txt +190 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ WORKDIR /code
7
+
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
+ RUN sudo apt-get install nodejs
12
+
13
+ COPY . .
14
+
15
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,9 +1,11 @@
1
  ---
2
  title: Hala Absher
3
- emoji: πŸ“‰
4
- colorFrom: red
5
- colorTo: indigo
6
- sdk: docker
 
 
7
  pinned: false
8
  license: cc
9
  ---
 
1
  ---
2
  title: Hala Absher
3
+ emoji: πŸŒ–
4
+ colorFrom: gray
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 3.18.0
8
+ app_file: app.py
9
  pinned: false
10
  license: cc
11
  ---
absher_user_guide_with_embeddings_1k.csv ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import pandas as pd
3
+ import numpy as np
4
+ import tiktoken
5
+ from openai.embeddings_utils import get_embedding, cosine_similarity
6
+ import translators as ts
7
+ import speech_recognition as sr
8
+ import gradio as gr
9
+ import openai
10
+ import subprocess
11
+
12
+
13
+ openai.api_key = "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"
14
+
15
+ df = pd.read_csv("absher_user_guide_with_embeddings_1k.csv")
16
+ df["embedding"] = df.embedding.apply(eval).apply(np.array)
17
+
18
+ def search_services(df, user_input, n=3, pprint=False):
19
+ product_embedding = get_embedding(
20
+ user_input,
21
+ engine="text-embedding-ada-002"
22
+ )
23
+ df["similarity"] = df.embedding.apply(lambda x: cosine_similarity(x, product_embedding))
24
+
25
+ results = (
26
+ df.sort_values("similarity", ascending=False)
27
+ .head(n)
28
+ .combined.str.replace("Title: ", "")
29
+ .str.replace("; Content:", ": ")
30
+ )
31
+ results = (
32
+ df.sort_values("similarity", ascending=False)
33
+ .head(n)
34
+ .Steps_Arabic
35
+ ).values[0]
36
+
37
+ if pprint:
38
+ for r in results:
39
+ print(r[:200])
40
+ print()
41
+ return results
42
+
43
+ def listen():
44
+ r = sr.Recognizer()
45
+
46
+ with sr.Microphone() as source:
47
+ print("May I help you?")
48
+ audio = r.listen(source)
49
+
50
+ try:
51
+ text = r.recognize_google(audio, language="ar-AE", show_all=False)
52
+ print("You said: " + text)
53
+ except sr.UnknownValueError:
54
+ print("Speech Recognition could not understand audio")
55
+ except sr.RequestError as e:
56
+ print("Could not request results from Speech Recognition service; {0}".format(e))
57
+
58
+ return text
59
+
60
+
61
+
62
+
63
+ def transcribe(audio_filepath):
64
+ harvard = sr.AudioFile(audio_filepath)
65
+ r = sr.Recognizer()
66
+ with harvard as source:
67
+ audio = r.record(source)
68
+ try:
69
+ text = r.recognize_google(audio, language="ar-AE", show_all=False)
70
+ print("You said: " + text)
71
+ except sr.UnknownValueError:
72
+ print("Speech Recognition could not understand audio")
73
+ except sr.RequestError as e:
74
+ print("Could not request results from Speech Recognition service; {0}".format(e))
75
+ return text
76
+
77
+ def run(audio_filepath):
78
+ text = transcribe(audio_filepath)
79
+ results = search_services(df, ts.translate_text(text), n=1)
80
+ return results
81
+
82
+ demo = gr.Interface(
83
+ fn=run,
84
+ inputs=gr.Audio(source="microphone", type="filepath"),
85
+ outputs="text").launch()
86
+
87
+ if __name__ == "__main__":
88
+ demo.launch()
89
+
90
+ # prompt = listen()
91
+ # results = search_services(df, ts.translate_text(prompt), n=3)
92
+
93
+ # print(results)
requirements.txt ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==22.1.0
2
+ aiohttp==3.8.3
3
+ aiosignal==1.3.1
4
+ aiosqlite==0.18.0
5
+ altair==4.2.2
6
+ anyio==3.6.2
7
+ appnope==0.1.3
8
+ argon2-cffi==21.3.0
9
+ argon2-cffi-bindings==21.2.0
10
+ arrow==1.2.3
11
+ asttokens==2.2.1
12
+ async-generator==1.10
13
+ async-timeout==4.0.2
14
+ attrs==22.2.0
15
+ Babel==2.11.0
16
+ backcall==0.2.0
17
+ backports.zoneinfo==0.2.1
18
+ beautifulsoup4==4.11.2
19
+ bleach==6.0.0
20
+ blobfile==2.0.1
21
+ certifi==2022.12.7
22
+ cffi==1.15.1
23
+ charset-normalizer==2.1.1
24
+ click==8.1.3
25
+ comm==0.1.2
26
+ contourpy==1.0.7
27
+ cryptography==39.0.1
28
+ cycler==0.11.0
29
+ datalib==0.0.0
30
+ debugpy==1.6.6
31
+ decorator==5.1.1
32
+ defusedxml==0.7.1
33
+ dill==0.3.6
34
+ docopt==0.6.2
35
+ embeddings==0.0.8
36
+ entrypoints==0.4
37
+ exceptiongroup==1.1.0
38
+ executing==1.2.0
39
+ fastapi==0.91.0
40
+ fastjsonschema==2.16.2
41
+ ffmpy==0.3.0
42
+ filelock==3.9.0
43
+ fonttools==4.38.0
44
+ fqdn==1.5.1
45
+ frozenlist==1.3.3
46
+ fsspec==2023.1.0
47
+ gradio==3.18.0
48
+ h11==0.14.0
49
+ httpcore==0.16.3
50
+ httpx==0.23.3
51
+ huggingface-hub==0.12.0
52
+ idna==3.4
53
+ importlib-metadata==6.0.0
54
+ importlib-resources==5.10.2
55
+ ipykernel==6.21.1
56
+ ipython==8.9.0
57
+ ipython-genutils==0.2.0
58
+ isoduration==20.11.0
59
+ jedi==0.18.2
60
+ Jinja2==3.1.2
61
+ joblib==1.2.0
62
+ Js2Py==0.74
63
+ json5==0.9.11
64
+ jsonpointer==2.3
65
+ jsonschema==4.17.3
66
+ jupyter-events==0.5.0
67
+ jupyter-ydoc==0.2.2
68
+ jupyter_client==8.0.2
69
+ jupyter_core==5.2.0
70
+ jupyter_server==2.2.1
71
+ jupyter_server_fileid==0.6.0
72
+ jupyter_server_terminals==0.4.4
73
+ jupyter_server_ydoc==0.6.1
74
+ jupyterlab==3.6.1
75
+ jupyterlab-pygments==0.2.2
76
+ jupyterlab_server==2.19.0
77
+ kiwisolver==1.4.4
78
+ linkify-it-py==1.0.3
79
+ lxml==4.9.2
80
+ markdown-it-py==2.1.0
81
+ MarkupSafe==2.1.2
82
+ matplotlib==3.6.3
83
+ matplotlib-inline==0.1.6
84
+ mdit-py-plugins==0.3.3
85
+ mdurl==0.1.2
86
+ mistune==2.0.5
87
+ multidict==6.0.4
88
+ multiprocess==0.70.14
89
+ nbclassic==0.5.1
90
+ nbclient==0.7.2
91
+ nbconvert==7.2.9
92
+ nbformat==5.7.3
93
+ ndg-httpsclient==0.5.1
94
+ nest-asyncio==1.5.6
95
+ notebook==6.5.2
96
+ notebook_shim==0.2.2
97
+ numpy==1.24.2
98
+ openai==0.26.5
99
+ orjson==3.8.6
100
+ outcome==1.2.0
101
+ packaging==23.0
102
+ pandas==1.5.3
103
+ pandocfilters==1.5.0
104
+ parso==0.8.3
105
+ pathos==0.3.0
106
+ pexpect==4.8.0
107
+ pickleshare==0.7.5
108
+ Pillow==9.4.0
109
+ pipwin==0.5.2
110
+ pkgutil_resolve_name==1.3.10
111
+ platformdirs==3.0.0
112
+ plotly==5.13.0
113
+ pox==0.3.2
114
+ ppft==1.7.6.6
115
+ prometheus-client==0.16.0
116
+ prompt-toolkit==3.0.36
117
+ psutil==5.9.4
118
+ ptyprocess==0.7.0
119
+ pure-eval==0.2.2
120
+ pyasn1==0.4.8
121
+ pycparser==2.21
122
+ pycryptodome==3.17
123
+ pycryptodomex==3.17
124
+ pydantic==1.10.4
125
+ pydub==0.25.1
126
+ PyExecJS==1.5.1
127
+ Pygments==2.14.0
128
+ pyjsparser==2.7.1
129
+ pyOpenSSL==23.0.0
130
+ pyparsing==3.0.9
131
+ PyPrind==2.11.3
132
+ pyrsistent==0.19.3
133
+ pySmartDL==1.3.4
134
+ PySocks==1.7.1
135
+ python-dateutil==2.8.2
136
+ python-json-logger==2.0.4
137
+ python-multipart==0.0.5
138
+ pytz==2022.7.1
139
+ pytz-deprecation-shim==0.1.0.post0
140
+ PyYAML==6.0
141
+ pyzmq==25.0.0
142
+ regex==2022.10.31
143
+ requests==2.28.2
144
+ rfc3339-validator==0.1.4
145
+ rfc3986==1.5.0
146
+ rfc3986-validator==0.1.1
147
+ scikit-learn==1.2.1
148
+ scipy==1.10.0
149
+ selenium==4.8.0
150
+ Send2Trash==1.8.0
151
+ six==1.16.0
152
+ sniffio==1.3.0
153
+ sortedcontainers==2.4.0
154
+ soupsieve==2.3.2.post1
155
+ SpeechRecognition==3.9.0
156
+ stack-data==0.6.2
157
+ starlette==0.24.0
158
+ tenacity==8.2.1
159
+ terminado==0.17.1
160
+ threadpoolctl==3.1.0
161
+ tiktoken==0.2.0
162
+ tinycss2==1.2.1
163
+ tokenizers==0.13.2
164
+ tomli==2.0.1
165
+ toolz==0.12.0
166
+ torch==1.13.1
167
+ tornado==6.2
168
+ tqdm==4.64.1
169
+ traitlets==5.9.0
170
+ transformers==4.26.0
171
+ translators==5.5.6
172
+ trio==0.22.0
173
+ trio-websocket==0.9.2
174
+ typing_extensions==4.4.0
175
+ tzdata==2022.7
176
+ tzlocal==4.2
177
+ uc-micro-py==1.0.1
178
+ uri-template==1.2.0
179
+ urllib3==1.26.14
180
+ uvicorn==0.20.0
181
+ wcwidth==0.2.6
182
+ webcolors==1.12
183
+ webencodings==0.5.1
184
+ websocket-client==1.5.1
185
+ websockets==10.4
186
+ wsproto==1.2.0
187
+ y-py==0.5.5
188
+ yarl==1.8.2
189
+ ypy-websocket==0.8.2
190
+ zipp==3.12.1