VuAI commited on
Commit
2dbfd9a
·
1 Parent(s): 96cbe92

Use login by supabase auth

Browse files
Files changed (1) hide show
  1. app.py +42 -17
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
- if username == os.getenv("username") and password == os.getenv("password"):
56
- return True
 
57
 
58
- if __name__ == "__main__":
59
- MODELS = ['VuAI/khi-van', 'VuAI/vi2vi_vn98']
 
 
 
 
 
 
 
60
 
61
- gr.Interface(fn=translator,
62
- inputs=[
63
- gr.inputs.Textbox(lines=5, label="Input Text"),
64
- gr.components.Dropdown(label="Select Model?", choices=MODELS, value=MODELS[0]),
65
- ],
66
- outputs=gr.inputs.Textbox(label="Result").style(show_copy_button=True),
67
- title="Translation Demo",
68
- examples = [
69
- ["Đây cũng là không có biện pháp sự tình, Vương Đằng Chi trước thì dùng thần hồn chi lực nhìn qua toàn bộ Thiên Thánh tông đệ tử, không có một cái có thể đạt tới Thái Sơ Thần Tông tuyển nhận tiêu chuẩn, mà lại Thiên Thánh tông đệ tử ưu tú thiên phú đều không khác mấy, không có đặc biệt xuất chúng tồn tại.",MODELS[0]],
70
- ['"Ba người các ngươi đi theo ta, ta trước mang các ngươi đi gặp Thái Sơ Thần Tông tông chủ đại nhân." Thiên Thánh tông tông chủ đối với trước mặt ba người nói.',MODELS[0]],
71
- ]
72
- ).launch(auth=login, auth_message="Chào mừng đến với VN98 Translator.")
 
 
 
 
 
 
 
 
 
 
 
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.")