Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 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 =
|
| 12 |
|
| 13 |
def get_oauth_info(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
|
| 14 |
global oauth_info
|
|
@@ -17,65 +17,43 @@ def get_oauth_info(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken |
|
|
| 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
|
| 36 |
-
dataset = 'Synaptics/COCO8'
|
| 37 |
-
return model.get_dataset(dataset, oauth_info['token'])
|
| 38 |
-
|
| 39 |
-
def run_training(epochs_text, batch_text):
|
| 40 |
|
| 41 |
-
try:
|
| 42 |
-
epochs = int(epochs_text)
|
| 43 |
-
batch = int(batch_text)
|
| 44 |
-
except Exception as e:
|
| 45 |
-
epochs = 100
|
| 46 |
-
batch = 16
|
| 47 |
-
print(f'ERROR converting {epochs_text}, and {batch_text}')
|
| 48 |
|
| 49 |
# Run the training
|
| 50 |
-
return model.run_training(epochs=epochs, batch=batch)
|
| 51 |
|
| 52 |
-
|
| 53 |
-
# Display message and run quantization
|
| 54 |
-
model.quantize()
|
| 55 |
-
return "Quantizing the trained model"
|
| 56 |
|
| 57 |
with gr.Blocks() as demo:
|
| 58 |
gr.LoginButton()
|
| 59 |
text1 = gr.Markdown("Starting to test SyNet")
|
| 60 |
user_text = gr.Markdown("")
|
| 61 |
|
| 62 |
-
|
| 63 |
-
load_text = gr.Markdown("Click to load dataset")
|
| 64 |
-
|
| 65 |
-
with gr.Row():
|
| 66 |
-
epochs_text = gr.Textbox(label='Epochs', value='100')
|
| 67 |
-
batch_text = gr.Textbox(label='Batch', value='16')
|
| 68 |
-
with gr.Column():
|
| 69 |
-
train_btn = gr.Button("Train")
|
| 70 |
-
train_text = gr.Markdown("Click to train")
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
load_btn.click(get_dataset, inputs=None, outputs=[load_text])
|
| 76 |
-
train_btn.click(run_training, inputs=[epochs_text, batch_text], outputs=[train_text])
|
| 77 |
-
quant_btn.click(quantize_model, inputs=None, outputs=[quant_text])
|
| 78 |
|
|
|
|
| 79 |
demo.load(get_oauth_info, inputs=None, outputs=user_text)
|
| 80 |
|
| 81 |
if __name__ == "__main__":
|
|
|
|
| 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 = HfApi()
|
| 12 |
|
| 13 |
def get_oauth_info(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
|
| 14 |
global oauth_info
|
|
|
|
| 17 |
print(f'profile = {profile}')
|
| 18 |
if profile is None:
|
| 19 |
oauth_info['username'] = None
|
| 20 |
+
oauth_info['token'] = None
|
|
|
|
|
|
|
| 21 |
return "Please login to the Huggingface with login button"
|
| 22 |
else:
|
| 23 |
#print(f'Testing {profile} for username')
|
| 24 |
oauth_info['username'] = profile.username
|
| 25 |
oauth_info['token'] = oauth_token.token
|
|
|
|
|
|
|
| 26 |
org_names = [org["name"] for org in whoami(oauth_token.token)["orgs"]]
|
| 27 |
|
| 28 |
return print(f'{profile.username}: {org_names}')
|
| 29 |
|
| 30 |
|
| 31 |
+
def compile_model(model_name):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
# try:
|
| 34 |
+
# epochs = int(epochs_text)
|
| 35 |
+
# batch = int(batch_text)
|
| 36 |
+
# except Exception as e:
|
| 37 |
+
# epochs = 100
|
| 38 |
+
# batch = 16
|
| 39 |
+
# print(f'ERROR converting {epochs_text}, and {batch_text}')
|
| 40 |
|
| 41 |
# Run the training
|
| 42 |
+
# return model.run_training(epochs=epochs, batch=batch)
|
| 43 |
|
| 44 |
+
return f"Compiled model {model_name}"
|
|
|
|
|
|
|
|
|
|
| 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 |
+
model_text = gr.Textbox(label='LiteRT Model', value='Synaptics/my_model')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
compile_btn = gr.Button("Compile Model")
|
| 54 |
+
compile_text = gr.Markdown("Click to load dataset")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
compile_btn.click(compile_model, inputs=[model_text], outputs=[compile_text])
|
| 57 |
demo.load(get_oauth_info, inputs=None, outputs=user_text)
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|