Use login by supabase auth
Browse files
app.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
| 1 |
import os, time, re
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
def inference(input_sentence, name_model):
|
| 7 |
# Load model
|
| 8 |
access_token = os.getenv("access_token")
|
|
@@ -51,22 +54,44 @@ def translator(input_sentence, name_model):
|
|
| 51 |
|
| 52 |
return result
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
def login(username, password):
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
gr.
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os, time, re
|
| 2 |
import gradio as gr
|
| 3 |
+
import supabase
|
| 4 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 5 |
|
| 6 |
+
# Initialize the Supabase client
|
| 7 |
+
client = supabase.create_client('https://zegvunzphdjucsvfkvky.supabase.co', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InplZ3Z1bnpwaGRqdWNzdmZrdmt5Iiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTY4NTgzMzg4OCwiZXhwIjoyMDAxNDA5ODg4fQ.g6tVWYkncmCXwbnjtMzi0vR860wZtAUpqELBMkOYDaU')
|
| 8 |
+
|
| 9 |
def inference(input_sentence, name_model):
|
| 10 |
# Load model
|
| 11 |
access_token = os.getenv("access_token")
|
|
|
|
| 54 |
|
| 55 |
return result
|
| 56 |
|
| 57 |
+
def words(input_sentence):
|
| 58 |
+
len_inp = len(input_sentence.replace('\n', ' ').replace(' ', ' ').replace(' ', ' ').strip().split(' '))
|
| 59 |
+
return 'Words: ' + str(len_inp) + ' / 9999'
|
| 60 |
+
|
| 61 |
def login(username, password):
|
| 62 |
+
# login
|
| 63 |
+
data = client.auth.sign_in_with_password({"email": username, "password": password})
|
| 64 |
+
return data
|
| 65 |
|
| 66 |
+
MODELS = ['VuAI/khi-van', 'VuAI/vi2vi_vn98']
|
| 67 |
+
|
| 68 |
+
curr_words = 9999
|
| 69 |
+
with gr.Blocks(title="Translator", theme=gr.themes.Default(primary_hue="red", secondary_hue="red")) as demo:
|
| 70 |
+
with gr.Row():
|
| 71 |
+
with gr.Column(scale=20):
|
| 72 |
+
gr.Text('VN98 Translation', show_label=False).style(container=False)
|
| 73 |
+
with gr.Column(scale=1, min_width=50):
|
| 74 |
+
darkBtn = gr.Button("Dark", variant='secondary', elem_id="darkTheme")
|
| 75 |
|
| 76 |
+
with gr.Row():
|
| 77 |
+
with gr.Column():
|
| 78 |
+
inp = gr.Textbox(lines=5, label="Input Text")
|
| 79 |
+
inp.input(fn=words, inputs=inp, outputs=gr.Text(show_label=False, value='Words: 0 / ' + str(curr_words)))
|
| 80 |
+
sel = gr.Dropdown(label="Select Model?", choices=MODELS, value=MODELS[0])
|
| 81 |
+
btn = gr.Button("Run", variant='primary')
|
| 82 |
+
with gr.Column():
|
| 83 |
+
out = gr.Textbox(lines=5, label="Result", interactive=True).style(show_copy_button=True)
|
| 84 |
+
|
| 85 |
+
changeTheme = """function changeTheme() {
|
| 86 |
+
body = document.querySelector('body').classList.toggle('dark');
|
| 87 |
+
btn_theme = document.querySelector('#darkTheme');
|
| 88 |
+
btn_theme.innerText = (btn_theme.innerText == 'Light') ? 'Dark' : 'Light';
|
| 89 |
+
}
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
+
btn.click(translator, inputs=[inp, sel], outputs=[out])
|
| 93 |
+
darkBtn.click(fn=None, _js=changeTheme)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
+
demo.launch(share=True, auth=login, auth_message="Chào mừng đến với VN98 Translator.")
|