Spaces:
Runtime error
Runtime error
Commit ·
6c8ec62
1
Parent(s): 6e3394c
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,44 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
interview=gr.load("qualz/interview", src="spaces",hf_token=os.environ["hf_token"])
|
| 4 |
-
interview.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
from database_helper import DatabaseIO
|
| 4 |
+
import pymongo
|
| 5 |
+
|
| 6 |
+
def check_credentials(email, password):
|
| 7 |
+
try:
|
| 8 |
+
with DatabaseIO(collection_name="Users") as db_io:
|
| 9 |
+
user_collection = db_io.collection
|
| 10 |
+
|
| 11 |
+
if not re.match(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$", email):
|
| 12 |
+
print("Email is invalid")
|
| 13 |
+
return False
|
| 14 |
+
|
| 15 |
+
print("Email is valid")
|
| 16 |
+
|
| 17 |
+
user = user_collection.find_one({"email": email})
|
| 18 |
+
|
| 19 |
+
# If email is not found, create a new email
|
| 20 |
+
if user is None:
|
| 21 |
+
new_email = {"email": email}
|
| 22 |
+
user_collection.insert_one(new_email)
|
| 23 |
+
print("New email created")
|
| 24 |
+
|
| 25 |
+
if user is not None:
|
| 26 |
+
with DatabaseIO(collection_name=os.environ['MONGO_COLLECTION_STUDIES']) as db_io_study:
|
| 27 |
+
study_collection = db_io_study.collection
|
| 28 |
+
study_id = ObjectId(password) # Convert the string to ObjectId
|
| 29 |
+
study = study_collection.find_one({"_id": study_id})
|
| 30 |
+
|
| 31 |
+
if study is not None:
|
| 32 |
+
return True
|
| 33 |
+
else:
|
| 34 |
+
return False
|
| 35 |
+
|
| 36 |
+
except pymongo.errors.ConnectionFailure as e:
|
| 37 |
+
print(f"Could not connect to MongoDB: {e}")
|
| 38 |
+
return False
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print(f"Error occurred: {e}")
|
| 41 |
+
return False
|
| 42 |
+
|
| 43 |
interview=gr.load("qualz/interview", src="spaces",hf_token=os.environ["hf_token"])
|
| 44 |
+
interview.launch(auth=check_credentials)
|