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+
from _vendor import vendor_llm_endpoint, vendor_llm_model
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# ====================================================================================================
|
| 5 |
+
|
| 6 |
+
theme = gr.themes.Base(
|
| 7 |
+
primary_hue="neutral",
|
| 8 |
+
secondary_hue="neutral",
|
| 9 |
+
neutral_hue="neutral",
|
| 10 |
+
text_size="lg",
|
| 11 |
+
font=[gr.themes.GoogleFont('Inter')],
|
| 12 |
+
font_mono=[gr.themes.GoogleFont('Ubuntu Mono')],
|
| 13 |
+
)
|
| 14 |
+
head = """
|
| 15 |
+
<link rel="icon" href="https://cdn.jsdelivr.net/gh/OneLevelStudio/CORE/STATIC/1LV_LOGO_DARK.png">
|
| 16 |
+
"""
|
| 17 |
+
css = """
|
| 18 |
+
#huggingface-space-header { display: none !important; }
|
| 19 |
+
* { -ms-overflow-style: none; scrollbar-width: none; }
|
| 20 |
+
*::-webkit-scrollbar { display: none; }
|
| 21 |
+
footer { display: none !important; }
|
| 22 |
+
textarea {
|
| 23 |
+
padding-top: 5px !important;
|
| 24 |
+
padding-bottom: 6px !important;
|
| 25 |
+
}
|
| 26 |
+
.gr_XX_B p {
|
| 27 |
+
font-size: 20px;
|
| 28 |
+
font-weight: 600;
|
| 29 |
+
text-transform: uppercase;
|
| 30 |
+
margin-top: 8px !important;
|
| 31 |
+
}
|
| 32 |
+
"""
|
| 33 |
+
offspellcheck = gr.InputHTMLAttributes(autocorrect="off", spellcheck=False)
|
| 34 |
+
|
| 35 |
+
# ====================================================================================================
|
| 36 |
+
|
| 37 |
+
def fn_process_multitextbox(gr_01_A):
|
| 38 |
+
gr_01_B = gr_01_A['text'].strip()
|
| 39 |
+
return "", gr_01_B
|
| 40 |
+
|
| 41 |
+
def fn_01(inputtext):
|
| 42 |
+
outputtext = ""
|
| 43 |
+
llm_res_stream = vendor_llm_endpoint.chat.completions.create(
|
| 44 |
+
model=vendor_llm_model,
|
| 45 |
+
messages=[{"role": "user", "content": f"""\
|
| 46 |
+
Your name is "Nyx WIKI", an AI assistant based on NYX models, developed by One Level Studio.
|
| 47 |
+
You have a clear, formal, neutral, and encyclopedic tone.
|
| 48 |
+
You provide accurate and well-structured information.
|
| 49 |
+
Do not give any link/url in response. Do not ask user anything.
|
| 50 |
+
This is user's input/question:
|
| 51 |
+
"{inputtext}"
|
| 52 |
+
"""}],
|
| 53 |
+
stream=True,
|
| 54 |
+
)
|
| 55 |
+
for event in llm_res_stream:
|
| 56 |
+
outputtext += event.choices[0].delta.content
|
| 57 |
+
yield outputtext
|
| 58 |
+
|
| 59 |
+
def fn_02(inputtext):
|
| 60 |
+
outputtext = ""
|
| 61 |
+
llm_res_stream = vendor_llm_endpoint.chat.completions.create(
|
| 62 |
+
model=vendor_llm_model,
|
| 63 |
+
messages=[{"role": "user", "content": f"""\
|
| 64 |
+
Your name is "Nyx EN2VI", an AI translator based on NYX models, developed by One Level Studio.
|
| 65 |
+
Do not give any link/url in response. Do not answer or ask user anything. Your only mission is translating the pure text.
|
| 66 |
+
Below is the pure text that user needs to translate. Translate it to Vietnamese (tiếng Việt):
|
| 67 |
+
"{inputtext}"
|
| 68 |
+
"""}],
|
| 69 |
+
stream=True,
|
| 70 |
+
)
|
| 71 |
+
for event in llm_res_stream:
|
| 72 |
+
outputtext += event.choices[0].delta.content
|
| 73 |
+
yield outputtext
|
| 74 |
+
|
| 75 |
+
def fn_03(inputtext):
|
| 76 |
+
outputtext = ""
|
| 77 |
+
llm_res_stream = vendor_llm_endpoint.chat.completions.create(
|
| 78 |
+
model=vendor_llm_model,
|
| 79 |
+
messages=[{"role": "user", "content": f"""\
|
| 80 |
+
Your name is "Nyx VI2EN", an AI translator based on NYX models, developed by One Level Studio.
|
| 81 |
+
Do not give any link/url in response. Do not answer or ask user anything. Your only mission is translating the pure text.
|
| 82 |
+
Below is the pure text that user needs to translate. Translate it to English:
|
| 83 |
+
"{inputtext}"
|
| 84 |
+
"""}],
|
| 85 |
+
stream=True,
|
| 86 |
+
)
|
| 87 |
+
for event in llm_res_stream:
|
| 88 |
+
outputtext += event.choices[0].delta.content
|
| 89 |
+
yield outputtext
|
| 90 |
+
|
| 91 |
+
# ====================================================================================================
|
| 92 |
+
|
| 93 |
+
with gr.Blocks() as app_001:
|
| 94 |
+
gr_01_A = gr.MultimodalTextbox(sources=[], placeholder="Ask Nyx anything", html_attributes= offspellcheck, autofocus=True, show_label=False, container=False)
|
| 95 |
+
gr_01_B = gr.Markdown(container=False, elem_classes="gr_XX_B")
|
| 96 |
+
gr_01_C = gr.Markdown(container=False)
|
| 97 |
+
gr.HTML("<div style='color: grey; text-align: center; font-size: 12px;'>Nyx can make mistakes, double-check information.<div>", container=False)
|
| 98 |
+
gr.on(
|
| 99 |
+
triggers=gr_01_A.submit,
|
| 100 |
+
fn=fn_process_multitextbox,
|
| 101 |
+
inputs=[gr_01_A], outputs=[gr_01_A, gr_01_B],
|
| 102 |
+
show_progress="hidden",
|
| 103 |
+
).then(
|
| 104 |
+
fn=fn_01,
|
| 105 |
+
inputs=[gr_01_B], outputs=[gr_01_C],
|
| 106 |
+
show_progress="full",
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
with gr.Blocks() as app_002:
|
| 110 |
+
gr_02_A = gr.MultimodalTextbox(sources=[], placeholder="Translate English to Vietnamese", html_attributes= offspellcheck, autofocus=True, show_label=False, container=False)
|
| 111 |
+
gr_02_B = gr.Markdown(container=False, elem_classes="gr_XX_B")
|
| 112 |
+
gr_02_C = gr.Markdown(container=False)
|
| 113 |
+
gr.on(
|
| 114 |
+
triggers=gr_02_A.submit,
|
| 115 |
+
fn=fn_process_multitextbox,
|
| 116 |
+
inputs=[gr_02_A], outputs=[gr_02_A, gr_02_B],
|
| 117 |
+
show_progress="hidden",
|
| 118 |
+
).then(
|
| 119 |
+
fn=fn_02,
|
| 120 |
+
inputs=[gr_02_B], outputs=[gr_02_C],
|
| 121 |
+
show_progress="full",
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
with gr.Blocks() as app_003:
|
| 125 |
+
gr_03_A = gr.MultimodalTextbox(sources=[], placeholder="Dịch tiếng Việt sang tiếng Anh", html_attributes= offspellcheck, autofocus=True, show_label=False, container=False)
|
| 126 |
+
gr_03_B = gr.Markdown(container=False, elem_classes="gr_XX_B")
|
| 127 |
+
gr_03_C = gr.Markdown(container=False)
|
| 128 |
+
gr.on(
|
| 129 |
+
triggers=gr_03_A.submit,
|
| 130 |
+
fn=fn_process_multitextbox,
|
| 131 |
+
inputs=[gr_03_A], outputs=[gr_03_A, gr_03_B],
|
| 132 |
+
show_progress="hidden",
|
| 133 |
+
).then(
|
| 134 |
+
fn=fn_03,
|
| 135 |
+
inputs=[gr_03_B], outputs=[gr_03_C],
|
| 136 |
+
show_progress="full",
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
with gr.Blocks() as app_about:
|
| 140 |
+
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)
|
| 141 |
+
|
| 142 |
+
# ====================================================================================================
|
| 143 |
+
|
| 144 |
+
with gr.Blocks(title="NYX") as demo:
|
| 145 |
+
with gr.Row():
|
| 146 |
+
with gr.Column():
|
| 147 |
+
gr.Markdown()
|
| 148 |
+
with gr.Column():
|
| 149 |
+
with gr.Tab("Nyx WIKI"):
|
| 150 |
+
app_001.render()
|
| 151 |
+
with gr.Tab("Nyx EN2VI"):
|
| 152 |
+
app_002.render()
|
| 153 |
+
with gr.Tab("Nyx VI2EN"):
|
| 154 |
+
app_003.render()
|
| 155 |
+
with gr.Tab("About"):
|
| 156 |
+
app_about.render()
|
| 157 |
+
with gr.Column():
|
| 158 |
+
gr.Markdown()
|
| 159 |
+
|
| 160 |
+
demo.launch(head=head, css=css, theme=theme)
|