Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,105 +1,105 @@
|
|
| 1 |
-
import app as gr
|
| 2 |
-
from auth import login, signup
|
| 3 |
-
from certificate_ai import read_pdf, verify_certificate
|
| 4 |
-
from db import cert_collection
|
| 5 |
-
|
| 6 |
-
current_user = {"username":None,"role":None}
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def user_login(username,password):
|
| 10 |
-
|
| 11 |
-
role = login(username,password)
|
| 12 |
-
|
| 13 |
-
if role == "user":
|
| 14 |
-
current_user["username"] = username
|
| 15 |
-
return "User Login Successful"
|
| 16 |
-
|
| 17 |
-
if role == "admin":
|
| 18 |
-
current_user["username"] = username
|
| 19 |
-
return "Admin Login Successful"
|
| 20 |
-
|
| 21 |
-
return "Invalid Login"
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def upload_certificate(file):
|
| 25 |
-
|
| 26 |
-
text = read_pdf(file)
|
| 27 |
-
|
| 28 |
-
result = verify_certificate(text)
|
| 29 |
-
|
| 30 |
-
cert_collection.insert_one({
|
| 31 |
-
"username":current_user["username"],
|
| 32 |
-
"certificate_text":text,
|
| 33 |
-
"result":result
|
| 34 |
-
})
|
| 35 |
-
|
| 36 |
-
return result
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
def view_certificates():
|
| 40 |
-
|
| 41 |
-
data = cert_collection.find()
|
| 42 |
-
|
| 43 |
-
output = []
|
| 44 |
-
|
| 45 |
-
for d in data:
|
| 46 |
-
output.append([d["username"],d["result"]])
|
| 47 |
-
|
| 48 |
-
return output
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
with gr.Blocks() as demo:
|
| 52 |
-
|
| 53 |
-
gr.Markdown("# Internship Certificate Verification System")
|
| 54 |
-
|
| 55 |
-
with gr.Tab("Signup"):
|
| 56 |
-
|
| 57 |
-
username = gr.Textbox(label="Username")
|
| 58 |
-
password = gr.Textbox(label="Password",type="password")
|
| 59 |
-
role = gr.Dropdown(["user","admin"])
|
| 60 |
-
|
| 61 |
-
signup_btn = gr.Button("Signup")
|
| 62 |
-
signup_output = gr.Textbox()
|
| 63 |
-
|
| 64 |
-
signup_btn.click(signup,
|
| 65 |
-
inputs=[username,password,role],
|
| 66 |
-
outputs=signup_output)
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
with gr.Tab("Login"):
|
| 70 |
-
|
| 71 |
-
l_user = gr.Textbox(label="Username")
|
| 72 |
-
l_pass = gr.Textbox(label="Password",type="password")
|
| 73 |
-
|
| 74 |
-
login_btn = gr.Button("Login")
|
| 75 |
-
login_output = gr.Textbox()
|
| 76 |
-
|
| 77 |
-
login_btn.click(user_login,
|
| 78 |
-
inputs=[l_user,l_pass],
|
| 79 |
-
outputs=login_output)
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
with gr.Tab("Upload Certificate"):
|
| 83 |
-
|
| 84 |
-
file = gr.File(label="Upload PDF")
|
| 85 |
-
|
| 86 |
-
verify_btn = gr.Button("Verify")
|
| 87 |
-
|
| 88 |
-
result = gr.Textbox(label="Result")
|
| 89 |
-
|
| 90 |
-
verify_btn.click(upload_certificate,
|
| 91 |
-
inputs=file,
|
| 92 |
-
outputs=result)
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
with gr.Tab("Admin Dashboard"):
|
| 96 |
-
|
| 97 |
-
view_btn = gr.Button("View Certificates")
|
| 98 |
-
|
| 99 |
-
table = gr.Dataframe(headers=["Username","Result"])
|
| 100 |
-
|
| 101 |
-
view_btn.click(view_certificates,
|
| 102 |
-
outputs=table)
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
demo.launch()
|
|
|
|
| 1 |
+
import app as gr
|
| 2 |
+
from auth import login, signup
|
| 3 |
+
from certificate_ai import read_pdf, verify_certificate
|
| 4 |
+
from db import cert_collection
|
| 5 |
+
|
| 6 |
+
current_user = {"username":None,"role":None}
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def user_login(username,password):
|
| 10 |
+
|
| 11 |
+
role = login(username,password)
|
| 12 |
+
|
| 13 |
+
if role == "user":
|
| 14 |
+
current_user["username"] = username
|
| 15 |
+
return "User Login Successful"
|
| 16 |
+
|
| 17 |
+
if role == "admin":
|
| 18 |
+
current_user["username"] = username
|
| 19 |
+
return "Admin Login Successful"
|
| 20 |
+
|
| 21 |
+
return "Invalid Login"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def upload_certificate(file):
|
| 25 |
+
|
| 26 |
+
text = read_pdf(file)
|
| 27 |
+
|
| 28 |
+
result = verify_certificate(text)
|
| 29 |
+
|
| 30 |
+
cert_collection.insert_one({
|
| 31 |
+
"username":current_user["username"],
|
| 32 |
+
"certificate_text":text,
|
| 33 |
+
"result":result
|
| 34 |
+
})
|
| 35 |
+
|
| 36 |
+
return result
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def view_certificates():
|
| 40 |
+
|
| 41 |
+
data = cert_collection.find()
|
| 42 |
+
|
| 43 |
+
output = []
|
| 44 |
+
|
| 45 |
+
for d in data:
|
| 46 |
+
output.append([d["username"],d["result"]])
|
| 47 |
+
|
| 48 |
+
return output
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
with gr.Blocks() as demo:
|
| 52 |
+
|
| 53 |
+
gr.Markdown("# Internship Certificate Verification System")
|
| 54 |
+
|
| 55 |
+
with gr.Tab("Signup"):
|
| 56 |
+
|
| 57 |
+
username = gr.Textbox(label="Username")
|
| 58 |
+
password = gr.Textbox(label="Password",type="password")
|
| 59 |
+
role = gr.Dropdown(["user","admin"])
|
| 60 |
+
|
| 61 |
+
signup_btn = gr.Button("Signup")
|
| 62 |
+
signup_output = gr.Textbox()
|
| 63 |
+
|
| 64 |
+
signup_btn.click(signup,
|
| 65 |
+
inputs=[username,password,role],
|
| 66 |
+
outputs=signup_output)
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
with gr.Tab("Login"):
|
| 70 |
+
|
| 71 |
+
l_user = gr.Textbox(label="Username")
|
| 72 |
+
l_pass = gr.Textbox(label="Password",type="password")
|
| 73 |
+
|
| 74 |
+
login_btn = gr.Button("Login")
|
| 75 |
+
login_output = gr.Textbox()
|
| 76 |
+
|
| 77 |
+
login_btn.click(user_login,
|
| 78 |
+
inputs=[l_user,l_pass],
|
| 79 |
+
outputs=login_output)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
with gr.Tab("Upload Certificate"):
|
| 83 |
+
|
| 84 |
+
file = gr.File(label="Upload PDF")
|
| 85 |
+
|
| 86 |
+
verify_btn = gr.Button("Verify")
|
| 87 |
+
|
| 88 |
+
result = gr.Textbox(label="Result")
|
| 89 |
+
|
| 90 |
+
verify_btn.click(upload_certificate,
|
| 91 |
+
inputs=file,
|
| 92 |
+
outputs=result)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
with gr.Tab("Admin Dashboard"):
|
| 96 |
+
|
| 97 |
+
view_btn = gr.Button("View Certificates")
|
| 98 |
+
|
| 99 |
+
table = gr.Dataframe(headers=["Username","Result"])
|
| 100 |
+
|
| 101 |
+
view_btn.click(view_certificates,
|
| 102 |
+
outputs=table)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
demo.launch(server_name="0.0.0.0",server_port=7860)
|