Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,14 +4,15 @@ import gradio as gr
|
|
| 4 |
from gradio_client import Client, handle_file
|
| 5 |
|
| 6 |
SPACE = "pockit-cloud/main"
|
| 7 |
-
|
| 8 |
-
# Connect to backend Space
|
| 9 |
client = Client(SPACE)
|
| 10 |
|
| 11 |
# -------------------------
|
| 12 |
-
# LOGIN
|
| 13 |
# -------------------------
|
| 14 |
def login(user_id, password):
|
|
|
|
|
|
|
|
|
|
| 15 |
try:
|
| 16 |
files, status = client.predict(
|
| 17 |
user_id=user_id,
|
|
@@ -26,6 +27,9 @@ def login(user_id, password):
|
|
| 26 |
# LIST FILES
|
| 27 |
# -------------------------
|
| 28 |
def list_files(user_id, password):
|
|
|
|
|
|
|
|
|
|
| 29 |
try:
|
| 30 |
files, status = client.predict(
|
| 31 |
user_id=user_id,
|
|
@@ -41,6 +45,9 @@ def list_files(user_id, password):
|
|
| 41 |
# -------------------------
|
| 42 |
def upload_file(user_id, password, file, custom_name):
|
| 43 |
|
|
|
|
|
|
|
|
|
|
| 44 |
if not file:
|
| 45 |
return "No file selected"
|
| 46 |
|
|
@@ -52,7 +59,7 @@ def upload_file(user_id, password, file, custom_name):
|
|
| 52 |
custom_name=custom_name if custom_name else os.path.basename(file),
|
| 53 |
api_name="/upload_file_secure"
|
| 54 |
)
|
| 55 |
-
return result[0]
|
| 56 |
except Exception as e:
|
| 57 |
return str(e)
|
| 58 |
|
|
@@ -61,6 +68,9 @@ def upload_file(user_id, password, file, custom_name):
|
|
| 61 |
# -------------------------
|
| 62 |
def download_file(user_id, password, filename):
|
| 63 |
|
|
|
|
|
|
|
|
|
|
| 64 |
if not filename:
|
| 65 |
return None
|
| 66 |
|
|
@@ -86,10 +96,13 @@ def download_file(user_id, password, filename):
|
|
| 86 |
return None
|
| 87 |
|
| 88 |
# -------------------------
|
| 89 |
-
#
|
| 90 |
# -------------------------
|
| 91 |
def change_password(user_id, password, new_password):
|
| 92 |
|
|
|
|
|
|
|
|
|
|
| 93 |
try:
|
| 94 |
result = client.predict(
|
| 95 |
user_id=user_id,
|
|
@@ -107,11 +120,9 @@ with gr.Blocks(title="Pockit Cloud Client") as app:
|
|
| 107 |
|
| 108 |
gr.Markdown("# ☁️ Pockit Cloud Client")
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
pw = gr.Textbox(label="Password", type="password", required=True)
|
| 113 |
|
| 114 |
-
# ---------------- LOGIN ----------------
|
| 115 |
with gr.Tab("Login"):
|
| 116 |
login_btn = gr.Button("Login")
|
| 117 |
login_status = gr.Textbox(label="Status")
|
|
@@ -123,7 +134,6 @@ with gr.Blocks(title="Pockit Cloud Client") as app:
|
|
| 123 |
outputs=[login_status, login_files]
|
| 124 |
)
|
| 125 |
|
| 126 |
-
# ---------------- FILES ----------------
|
| 127 |
with gr.Tab("Files"):
|
| 128 |
|
| 129 |
refresh_btn = gr.Button("Refresh File List")
|
|
@@ -158,9 +168,7 @@ with gr.Blocks(title="Pockit Cloud Client") as app:
|
|
| 158 |
outputs=upload_status
|
| 159 |
)
|
| 160 |
|
| 161 |
-
# ---------------- PASSWORD ----------------
|
| 162 |
with gr.Tab("Password"):
|
| 163 |
-
|
| 164 |
new_pw = gr.Textbox(label="New Password", type="password")
|
| 165 |
change_btn = gr.Button("Change Password")
|
| 166 |
change_status = gr.Textbox(label="Status")
|
|
|
|
| 4 |
from gradio_client import Client, handle_file
|
| 5 |
|
| 6 |
SPACE = "pockit-cloud/main"
|
|
|
|
|
|
|
| 7 |
client = Client(SPACE)
|
| 8 |
|
| 9 |
# -------------------------
|
| 10 |
+
# LOGIN
|
| 11 |
# -------------------------
|
| 12 |
def login(user_id, password):
|
| 13 |
+
if not user_id or not password:
|
| 14 |
+
return "Username and password required", []
|
| 15 |
+
|
| 16 |
try:
|
| 17 |
files, status = client.predict(
|
| 18 |
user_id=user_id,
|
|
|
|
| 27 |
# LIST FILES
|
| 28 |
# -------------------------
|
| 29 |
def list_files(user_id, password):
|
| 30 |
+
if not user_id or not password:
|
| 31 |
+
return "Username and password required", []
|
| 32 |
+
|
| 33 |
try:
|
| 34 |
files, status = client.predict(
|
| 35 |
user_id=user_id,
|
|
|
|
| 45 |
# -------------------------
|
| 46 |
def upload_file(user_id, password, file, custom_name):
|
| 47 |
|
| 48 |
+
if not user_id or not password:
|
| 49 |
+
return "Username and password required"
|
| 50 |
+
|
| 51 |
if not file:
|
| 52 |
return "No file selected"
|
| 53 |
|
|
|
|
| 59 |
custom_name=custom_name if custom_name else os.path.basename(file),
|
| 60 |
api_name="/upload_file_secure"
|
| 61 |
)
|
| 62 |
+
return result[0]
|
| 63 |
except Exception as e:
|
| 64 |
return str(e)
|
| 65 |
|
|
|
|
| 68 |
# -------------------------
|
| 69 |
def download_file(user_id, password, filename):
|
| 70 |
|
| 71 |
+
if not user_id or not password:
|
| 72 |
+
return None
|
| 73 |
+
|
| 74 |
if not filename:
|
| 75 |
return None
|
| 76 |
|
|
|
|
| 96 |
return None
|
| 97 |
|
| 98 |
# -------------------------
|
| 99 |
+
# PASSWORD CHANGE
|
| 100 |
# -------------------------
|
| 101 |
def change_password(user_id, password, new_password):
|
| 102 |
|
| 103 |
+
if not user_id or not password or not new_password:
|
| 104 |
+
return "All fields required"
|
| 105 |
+
|
| 106 |
try:
|
| 107 |
result = client.predict(
|
| 108 |
user_id=user_id,
|
|
|
|
| 120 |
|
| 121 |
gr.Markdown("# ☁️ Pockit Cloud Client")
|
| 122 |
|
| 123 |
+
user = gr.Textbox(label="User ID")
|
| 124 |
+
pw = gr.Textbox(label="Password", type="password")
|
|
|
|
| 125 |
|
|
|
|
| 126 |
with gr.Tab("Login"):
|
| 127 |
login_btn = gr.Button("Login")
|
| 128 |
login_status = gr.Textbox(label="Status")
|
|
|
|
| 134 |
outputs=[login_status, login_files]
|
| 135 |
)
|
| 136 |
|
|
|
|
| 137 |
with gr.Tab("Files"):
|
| 138 |
|
| 139 |
refresh_btn = gr.Button("Refresh File List")
|
|
|
|
| 168 |
outputs=upload_status
|
| 169 |
)
|
| 170 |
|
|
|
|
| 171 |
with gr.Tab("Password"):
|
|
|
|
| 172 |
new_pw = gr.Textbox(label="New Password", type="password")
|
| 173 |
change_btn = gr.Button("Change Password")
|
| 174 |
change_status = gr.Textbox(label="Status")
|