Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,37 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
-
#import sys
|
| 4 |
-
#import os
|
| 5 |
import training
|
|
|
|
|
|
|
| 6 |
|
| 7 |
model = training.model_training()
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
def get_dataset():
|
| 10 |
global dataset_cfg
|
| 11 |
|
|
@@ -18,8 +44,9 @@ def run_training():
|
|
| 18 |
return model.run_training()
|
| 19 |
|
| 20 |
with gr.Blocks() as demo:
|
|
|
|
| 21 |
text1 = gr.Markdown("Starting to test SyNet")
|
| 22 |
-
|
| 23 |
|
| 24 |
load_btn = gr.Button("Load dataset")
|
| 25 |
load_text = gr.Markdown("")
|
|
@@ -30,6 +57,7 @@ with gr.Blocks() as demo:
|
|
| 30 |
load_btn.click(get_dataset, inputs=None, outputs=[load_text])
|
| 31 |
train_btn.click(run_training, inputs=None, outputs=[train_text])
|
| 32 |
|
|
|
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
| 35 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
|
|
|
|
|
|
| 3 |
import training
|
| 4 |
+
from huggingface_hub import HfApi
|
| 5 |
+
from huggingface_hub import whoami
|
| 6 |
|
| 7 |
model = training.model_training()
|
| 8 |
|
| 9 |
+
# Get top-level authorizations
|
| 10 |
+
oauth_info = {'username' : None, 'token' : None}
|
| 11 |
+
api = None
|
| 12 |
+
|
| 13 |
+
def get_oauth_info(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
|
| 14 |
+
global oauth_info
|
| 15 |
+
global api
|
| 16 |
+
|
| 17 |
+
print(f'profile = {profile}')
|
| 18 |
+
if profile is None:
|
| 19 |
+
oauth_info['username'] = None
|
| 20 |
+
oauth_info['token'] = None
|
| 21 |
+
api = HfApi()
|
| 22 |
+
|
| 23 |
+
return "Please login to the Huggingface with login button"
|
| 24 |
+
else:
|
| 25 |
+
#print(f'Testing {profile} for username')
|
| 26 |
+
oauth_info['username'] = profile.username
|
| 27 |
+
oauth_info['token'] = oauth_token.token
|
| 28 |
+
|
| 29 |
+
api = HfApi(token=oauth_token.token)
|
| 30 |
+
org_names = [org["name"] for org in whoami(oauth_token.token)["orgs"]]
|
| 31 |
+
|
| 32 |
+
return print(f'{profile.username}: {org_names}')
|
| 33 |
+
|
| 34 |
+
|
| 35 |
def get_dataset():
|
| 36 |
global dataset_cfg
|
| 37 |
|
|
|
|
| 44 |
return model.run_training()
|
| 45 |
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
+
gr.LoginButton()
|
| 48 |
text1 = gr.Markdown("Starting to test SyNet")
|
| 49 |
+
user_text = gr.Markdown("")
|
| 50 |
|
| 51 |
load_btn = gr.Button("Load dataset")
|
| 52 |
load_text = gr.Markdown("")
|
|
|
|
| 57 |
load_btn.click(get_dataset, inputs=None, outputs=[load_text])
|
| 58 |
train_btn.click(run_training, inputs=None, outputs=[train_text])
|
| 59 |
|
| 60 |
+
demo.load(get_oauth_info, inputs=None, outputs=user_text)
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
| 63 |
demo.launch()
|