rukeshpaudel's picture
Update app.py
cda8418
import gradio as gr
import os
from database_helper import DatabaseIO
import pymongo
import re
from bson import ObjectId
def check_credentials(email, password):
try:
with DatabaseIO(collection_name=os.environ['MONGO_COLLECTION_INTERVIEWEES']) as db_io:
user_collection = db_io.collection
if not re.match(r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$", email):
print("Email is invalid")
return False
print("Email is valid")
user = user_collection.find_one({"email": email})
# If email is not found, create a new email
if user is None:
new_email = {"email": email}
user_collection.insert_one(new_email)
print("New email created")
with DatabaseIO(collection_name=os.environ['MONGO_COLLECTION_STUDIES']) as db_io_study:
study_collection = db_io_study.collection
study_id = ObjectId(password) # Convert the string to ObjectId
study = study_collection.find_one({"_id": study_id})
if study is not None:
return True
else:
return False
if user is not None:
with DatabaseIO(collection_name=os.environ['MONGO_COLLECTION_STUDIES']) as db_io_study:
study_collection = db_io_study.collection
study_id = ObjectId(password) # Convert the string to ObjectId
study = study_collection.find_one({"_id": study_id})
if study is not None:
return True
else:
return False
except pymongo.errors.ConnectionFailure as e:
print(f"Could not connect to MongoDB: {e}")
return False
except Exception as e:
print(f"Error occurred: {e}")
return False
interview=gr.load("qualz/interview", src="spaces",hf_token=os.environ["hf_token"])
interview.launch(auth=check_credentials)