File size: 6,122 Bytes
1d77098
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
990a60d
1d77098
 
 
 
 
 
 
 
 
 
 
 
 
 
 
990a60d
1d77098
 
 
 
 
 
 
 
 
 
 
 
 
 
990a60d
1d77098
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from _vendor import vendor_llm_endpoint, vendor_llm_model
import gradio as gr

# ====================================================================================================

theme = gr.themes.Base(
    primary_hue="neutral",
    secondary_hue="neutral",
    neutral_hue="neutral",
    text_size="lg",
    font=[gr.themes.GoogleFont('Inter')], 
    font_mono=[gr.themes.GoogleFont('Ubuntu Mono')],
)
head = """
<link rel="icon" href="https://cdn.jsdelivr.net/gh/OneLevelStudio/CORE/STATIC/1LV_LOGO_DARK.png">
"""
css = """
#huggingface-space-header { display: none !important; }
* { -ms-overflow-style: none; scrollbar-width: none; }
*::-webkit-scrollbar { display: none; }
footer { display: none !important; }
textarea {
    padding-top: 5px !important;
    padding-bottom: 6px !important;
}
.gr_XX_B p {
    font-size: 20px;
    font-weight: 600;
    text-transform: uppercase;
    margin-top: 8px !important;
}
"""
offspellcheck = gr.InputHTMLAttributes(autocorrect="off", spellcheck=False)

# ====================================================================================================

def fn_process_multitextbox(gr_01_A):
    gr_01_B = gr_01_A['text'].strip()
    return "", gr_01_B

def fn_01(inputtext):
    outputtext = ""
    llm_res_stream = vendor_llm_endpoint.chat.completions.create(
        model=vendor_llm_model,
        messages=[{"role": "user", "content": f"""\
Your name is "Nyx WIKI", an AI assistant based on NYX models, developed by One Level Studio.
You have a clear, formal, neutral, and encyclopedic tone.
You provide accurate and well-structured information.
Do not give any link/url in response. Do not ask user anything.
This is user's input/question:
"{inputtext}"
"""}],
        stream=True,
    )
    for event in llm_res_stream:
        outputtext += event.choices[0].delta.content
        yield outputtext

def fn_02(inputtext):
    outputtext = ""
    llm_res_stream = vendor_llm_endpoint.chat.completions.create(
        model=vendor_llm_model,
        messages=[{"role": "user", "content": f"""\
Your name is "Nyx EN2VI", an AI translator based on NYX models, developed by One Level Studio.
Do not give any link/url in response. Do not answer or ask user anything. Your only mission is translating the pure text.
Below is the pure text that user needs to translate. Translate it to Vietnamese (tiếng Việt):
"{inputtext}"
"""}],
        stream=True,
    )
    for event in llm_res_stream:
        outputtext += event.choices[0].delta.content
        yield outputtext

def fn_03(inputtext):
    outputtext = ""
    llm_res_stream = vendor_llm_endpoint.chat.completions.create(
        model=vendor_llm_model,
        messages=[{"role": "user", "content": f"""\
Your name is "Nyx VI2EN", an AI translator based on NYX models, developed by One Level Studio.
Do not give any link/url in response. Do not answer or ask user anything. Your only mission is translating the pure text.
Below is the pure text that user needs to translate. Translate it to English:
"{inputtext}"
"""}],
        stream=True,
    )
    for event in llm_res_stream:
        outputtext += event.choices[0].delta.content
        yield outputtext

# ====================================================================================================

with gr.Blocks() as app_001:
    gr_01_A = gr.MultimodalTextbox(sources=[], placeholder="Ask Nyx anything", max_plain_text_length=99999, html_attributes= offspellcheck, autofocus=True, show_label=False, container=False)
    gr_01_B = gr.Markdown(container=False, elem_classes="gr_XX_B")
    gr_01_C = gr.Markdown(container=False)
    gr.HTML("<div style='color: grey; text-align: center; font-size: 12px;'>Nyx can make mistakes, double-check information.<div>", container=False)
    gr.on(
        triggers=gr_01_A.submit,
        fn=fn_process_multitextbox,
        inputs=[gr_01_A], outputs=[gr_01_A, gr_01_B],
        show_progress="hidden",
    ).then(
        fn=fn_01,
        inputs=[gr_01_B], outputs=[gr_01_C],
        show_progress="full",
    )

with gr.Blocks() as app_002:
    gr_02_A = gr.MultimodalTextbox(sources=[], placeholder="Translate English to Vietnamese", max_plain_text_length=99999, html_attributes= offspellcheck, autofocus=True, show_label=False, container=False)
    gr_02_B = gr.Markdown(container=False, elem_classes="gr_XX_B")
    gr_02_C = gr.Markdown(container=False)
    gr.on(
        triggers=gr_02_A.submit,
        fn=fn_process_multitextbox,
        inputs=[gr_02_A], outputs=[gr_02_A, gr_02_B],
        show_progress="hidden",
    ).then(
        fn=fn_02,
        inputs=[gr_02_B], outputs=[gr_02_C],
        show_progress="full",
    )

with gr.Blocks() as app_003:
    gr_03_A = gr.MultimodalTextbox(sources=[], placeholder="Dịch tiếng Việt sang tiếng Anh", max_plain_text_length=99999, html_attributes= offspellcheck, autofocus=True, show_label=False, container=False)
    gr_03_B = gr.Markdown(container=False, elem_classes="gr_XX_B")
    gr_03_C = gr.Markdown(container=False)
    gr.on(
        triggers=gr_03_A.submit,
        fn=fn_process_multitextbox,
        inputs=[gr_03_A], outputs=[gr_03_A, gr_03_B],
        show_progress="hidden",
    ).then(
        fn=fn_03,
        inputs=[gr_03_B], outputs=[gr_03_C],
        show_progress="full",
    )

with gr.Blocks() as app_about:
    gr.HTML("<div style='text-align: center;'><br>NYX, developed by One Level Studio.<br><br><a href='https://onelevel.studio' target='_blank'>onelevel.studio</a><div>", container=False)

# ====================================================================================================

with gr.Blocks(title="NYX") as demo:
    with gr.Row():
        with gr.Column():
            gr.Markdown()
        with gr.Column():
            with gr.Tab("Nyx WIKI"):
                app_001.render()
            with gr.Tab("Nyx EN2VI"):
                app_002.render()
            with gr.Tab("Nyx VI2EN"):
                app_003.render()
            with gr.Tab("About"):
                app_about.render()
        with gr.Column():
            gr.Markdown()

demo.launch(head=head, css=css, theme=theme)