prwlnght rukeshpaudel commited on
Commit
f7fe4ff
·
0 Parent(s):

Duplicate from qualz/interview_public

Browse files

Co-authored-by: Rukesh Paudel <rukeshpaudel@users.noreply.huggingface.co>

Files changed (5) hide show
  1. .gitignore +241 -0
  2. README.md +6 -0
  3. app.py +56 -0
  4. database_helper.py +92 -0
  5. requirements.txt +13 -0
.gitignore ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # project specific
2
+ .env
3
+ dev_credentials.json
4
+ dev/
5
+
6
+ # Byte-compiled / optimized / DLL files
7
+ __pycache__/
8
+ *.py[cod]
9
+ *$py.class
10
+
11
+ # C extensions
12
+ *.so
13
+
14
+ # Distribution / packaging
15
+ .Python
16
+ build/
17
+ develop-eggs/
18
+ dist/
19
+ downloads/
20
+ eggs/
21
+ .eggs/
22
+ lib/
23
+ lib64/
24
+ parts/
25
+ sdist/
26
+ var/
27
+ wheels/
28
+ share/python-wheels/
29
+ *.egg-info/
30
+ .installed.cfg
31
+ *.egg
32
+ MANIFEST
33
+
34
+ # PyInstaller
35
+ # Usually these files are written by a python script from a template
36
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
37
+ *.manifest
38
+ *.spec
39
+
40
+ # Installer logs
41
+ pip-log.txt
42
+ pip-delete-this-directory.txt
43
+
44
+ # Unit test / coverage reports
45
+ htmlcov/
46
+ .tox/
47
+ .nox/
48
+ .coverage
49
+ .coverage.*
50
+ .cache
51
+ nosetests.xml
52
+ coverage.xml
53
+ *.cover
54
+ *.py,cover
55
+ .hypothesis/
56
+ .pytest_cache/
57
+ cover/
58
+
59
+ # Translations
60
+ *.mo
61
+ *.pot
62
+
63
+ # Django stuff:
64
+ *.log
65
+ local_settings.py
66
+ db.sqlite3
67
+ db.sqlite3-journal
68
+
69
+ # Flask stuff:
70
+ instance/
71
+ .webassets-cache
72
+
73
+ # Scrapy stuff:
74
+ .scrapy
75
+
76
+ # Sphinx documentation
77
+ docs/_build/
78
+
79
+ # PyBuilder
80
+ .pybuilder/
81
+ target/
82
+
83
+ # Jupyter Notebook
84
+ .ipynb_checkpoints
85
+
86
+ # IPython
87
+ profile_default/
88
+ ipython_config.py
89
+
90
+ # pyenv
91
+ # For a library or package, you might want to ignore these files since the code is
92
+ # intended to run in multiple environments; otherwise, check them in:
93
+ # .python-version
94
+
95
+ # pipenv
96
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
98
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
99
+ # install all needed dependencies.
100
+ #Pipfile.lock
101
+
102
+ # poetry
103
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
104
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
105
+ # commonly ignored for libraries.
106
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
107
+ #poetry.lock
108
+
109
+ # pdm
110
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
111
+ #pdm.lock
112
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
113
+ # in version control.
114
+ # https://pdm.fming.dev/#use-with-ide
115
+ .pdm.toml
116
+
117
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
118
+ __pypackages__/
119
+
120
+ # Celery stuff
121
+ celerybeat-schedule
122
+ celerybeat.pid
123
+
124
+ # SageMath parsed files
125
+ *.sage.py
126
+
127
+ # Environments
128
+ .venv
129
+ env/
130
+ venv/
131
+ ENV/
132
+ env.bak/
133
+ venv.bak/
134
+
135
+ # Spyder project settings
136
+ .spyderproject
137
+ .spyproject
138
+
139
+ # Rope project settings
140
+ .ropeproject
141
+
142
+ # mkdocs documentation
143
+ /site
144
+
145
+ # mypy
146
+ .mypy_cache/
147
+ .dmypy.json
148
+ dmypy.json
149
+
150
+ # Pyre type checker
151
+ .pyre/
152
+
153
+ # pytype static type analyzer
154
+ .pytype/
155
+
156
+ # Cython debug symbols
157
+ cython_debug/
158
+
159
+ # PyCharm
160
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
161
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
162
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
163
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
164
+ .idea/
165
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
166
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
167
+
168
+ # User-specific stuff
169
+ .idea/**/workspace.xml
170
+ .idea/**/tasks.xml
171
+ .idea/**/usage.statistics.xml
172
+ .idea/**/dictionaries
173
+ .idea/**/shelf
174
+
175
+ # AWS User-specific
176
+ .idea/**/aws.xml
177
+
178
+ # Generated files
179
+ .idea/**/contentModel.xml
180
+
181
+ # Sensitive or high-churn files
182
+ .idea/**/dataSources/
183
+ .idea/**/dataSources.ids
184
+ .idea/**/dataSources.local.xml
185
+ .idea/**/sqlDataSources.xml
186
+ .idea/**/dynamic.xml
187
+ .idea/**/uiDesigner.xml
188
+ .idea/**/dbnavigator.xml
189
+
190
+ # Gradle
191
+ .idea/**/gradle.xml
192
+ .idea/**/libraries
193
+
194
+ # Gradle and Maven with auto-import
195
+ # When using Gradle or Maven with auto-import, you should exclude module files,
196
+ # since they will be recreated, and may cause churn. Uncomment if using
197
+ # auto-import.
198
+ # .idea/artifacts
199
+ # .idea/compiler.xml
200
+ # .idea/jarRepositories.xml
201
+ # .idea/modules.xml
202
+ # .idea/*.iml
203
+ # .idea/modules
204
+ # *.iml
205
+ # *.ipr
206
+
207
+ # CMake
208
+ cmake-build-*/
209
+
210
+ # Mongo Explorer plugin
211
+ .idea/**/mongoSettings.xml
212
+
213
+ # File-based project format
214
+ *.iws
215
+
216
+ # IntelliJ
217
+ out/
218
+
219
+ # mpeltonen/sbt-idea plugin
220
+ .idea_modules/
221
+
222
+ # JIRA plugin
223
+ atlassian-ide-plugin.xml
224
+
225
+ # Cursive Clojure plugin
226
+ .idea/replstate.xml
227
+
228
+ # SonarLint plugin
229
+ .idea/sonarlint/
230
+
231
+ # Crashlytics plugin (for Android Studio and IntelliJ)
232
+ com_crashlytics_export_strings.xml
233
+ crashlytics.properties
234
+ crashlytics-build.properties
235
+ fabric.properties
236
+
237
+ # Editor-based Rest Client
238
+ .idea/httpRequests
239
+
240
+ # Android studio 3.1+ serialized cache file
241
+ .idea/caches/build_file_checksums.ser
README.md ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ ---
2
+ sdk: gradio
3
+ emoji: 📚
4
+ app_file: app.py
5
+ duplicated_from: qualz/interview_public
6
+ ---
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from database_helper import DatabaseIO
4
+ import pymongo
5
+ import re
6
+ from bson import ObjectId
7
+
8
+
9
+ def check_credentials(email, password):
10
+ try:
11
+ with DatabaseIO(collection_name=os.environ['MONGO_COLLECTION_INTERVIEWEES']) as db_io:
12
+ user_collection = db_io.collection
13
+
14
+ if not re.match(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$", email):
15
+ print("Email is invalid")
16
+ return False
17
+
18
+ print("Email is valid")
19
+
20
+ user = user_collection.find_one({"email": email})
21
+
22
+ # If email is not found, create a new email
23
+ if user is None:
24
+ new_email = {"email": email}
25
+ user_collection.insert_one(new_email)
26
+ print("New email created")
27
+ with DatabaseIO(collection_name=os.environ['MONGO_COLLECTION_STUDIES']) as db_io_study:
28
+ study_collection = db_io_study.collection
29
+ study_id = ObjectId(password) # Convert the string to ObjectId
30
+ study = study_collection.find_one({"_id": study_id})
31
+
32
+ if study is not None:
33
+ return True
34
+ else:
35
+ return False
36
+
37
+ if user is not None:
38
+ with DatabaseIO(collection_name=os.environ['MONGO_COLLECTION_STUDIES']) as db_io_study:
39
+ study_collection = db_io_study.collection
40
+ study_id = ObjectId(password) # Convert the string to ObjectId
41
+ study = study_collection.find_one({"_id": study_id})
42
+
43
+ if study is not None:
44
+ return True
45
+ else:
46
+ return False
47
+
48
+ except pymongo.errors.ConnectionFailure as e:
49
+ print(f"Could not connect to MongoDB: {e}")
50
+ return False
51
+ except Exception as e:
52
+ print(f"Error occurred: {e}")
53
+ return False
54
+
55
+ interview=gr.load("qualz/interview", src="spaces",hf_token=os.environ["hf_token"])
56
+ interview.launch(auth=check_credentials)
database_helper.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+
3
+ import pymongo
4
+ from pymongo.errors import PyMongoError
5
+ import os
6
+ import dotenv
7
+ from pymongo.server_api import ServerApi
8
+
9
+ class DatabaseIO:
10
+ def __init__(self, db_name=None, collection_name=None):
11
+ dotenv.load_dotenv()
12
+
13
+ mongo_username = os.environ['MONGO_USERNAME']
14
+ mongo_password = os.environ['MONGO_PASSWORD']
15
+ client_url = os.environ['MONGO_CLIENT_URL_DEV']
16
+ uri = f"mongodb+srv://{mongo_username}:{mongo_password}@{client_url}/?retryWrites=true&w=majority"
17
+
18
+ if not db_name:
19
+ db_name = os.environ['MONGO_DATABASE_NAME']
20
+ if not collection_name:
21
+ collection_name = os.environ['MONGO_COLLECTION']
22
+
23
+ self.client = pymongo.MongoClient(uri, server_api=ServerApi('1'))
24
+ self.db = self.client[db_name]
25
+ self.collection = self.db[collection_name]
26
+
27
+ def insert_document(self, article, collection=None, unique_on='_id', upsert=False):
28
+
29
+ if not collection:
30
+ collection = self.collection
31
+
32
+ article['date_modified'] = datetime.now().utcnow()
33
+ existing_document = collection.find_one({unique_on: article[unique_on]})
34
+ if existing_document:
35
+ # there is something like with the reddit id already
36
+
37
+ if upsert:
38
+ collection.update_one({unique_on: article[unique_on]}, {"$set": article})
39
+ else:
40
+ article['date_created'] = datetime.now().utcnow()
41
+ collection.insert_one(article)
42
+
43
+ def __enter__(self):
44
+ return self
45
+
46
+ def __exit__(self, exc_type, exc_value, traceback):
47
+ try:
48
+ self.client.close()
49
+ except PyMongoError as e:
50
+ print(f"An error occurred while closing the database connection: {e}")
51
+ raise
52
+
53
+ def __del__(self):
54
+ try:
55
+ self.client.close()
56
+ except Exception as e:
57
+ print(e)
58
+
59
+ def read_documents(self, query=None, sort_by=None, sort_order=None):
60
+ if query is None:
61
+ query = {}
62
+ try:
63
+ if sort_by:
64
+ if not sort_order or sort_order not in [1, -1]:
65
+ sort_order= 1
66
+ for article in self.collection.find(query).sort(sort_by, sort_order):
67
+ yield article
68
+ else:
69
+ for article in self.collection.find(query):
70
+ yield article
71
+ except Exception as e:
72
+ print(e)
73
+
74
+ def count_documents(self, query=None):
75
+ if query is None:
76
+ query = {}
77
+ try:
78
+ return self.collection.count_documents(query)
79
+ except Exception as e:
80
+ print(e)
81
+
82
+ def update_documents(self, query, update, upsert=True):
83
+ try:
84
+ self.collection.update_one(query, update, upsert=upsert)
85
+ except Exception as e:
86
+ print(e)
87
+
88
+ def delete_document(self, query):
89
+ try:
90
+ self.collection.delete_one(query)
91
+ except Exception as e:
92
+ print(e)
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ bcrypt~=4.0
2
+ elevenlabs~=0.2
3
+ gradio~=3.36
4
+ gradio_client~=0.2
5
+ huggingface-hub~=0.16
6
+ langchain~=0.0
7
+ numpy~=1.25
8
+ openai~=0.27
9
+ pandas~=2.0
10
+ pymongo~=4.4
11
+ python-dotenv~=1.0
12
+ regex~=2023.6
13
+ uvicorn~=0.22