Spaces:
Sleeping
Sleeping
phucpx
commited on
Commit
·
d20f3c3
1
Parent(s):
6cf1fe6
add passsage templates
Browse files
app.py
CHANGED
|
@@ -5,7 +5,21 @@ import json
|
|
| 5 |
import requests
|
| 6 |
import random
|
| 7 |
|
| 8 |
-
API_URL = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
DISABLED = os.getenv("DISABLED") == 'True'
|
| 10 |
BEARER_TOKEN = "Prep@123"
|
| 11 |
NUM_THREADS = 16
|
|
@@ -22,7 +36,7 @@ sys.excepthook = exception_handler
|
|
| 22 |
sys.tracebacklimit = 0
|
| 23 |
|
| 24 |
|
| 25 |
-
def predict(system_prompt, inputs, top_p, temperature, max_tokens, chat_counter, chatbot, history, request: gr.Request):
|
| 26 |
messages = [{"role": "system", "content": system_prompt}] if system_prompt else []
|
| 27 |
|
| 28 |
headers = {
|
|
@@ -87,7 +101,7 @@ def predict(system_prompt, inputs, top_p, temperature, max_tokens, chat_counter,
|
|
| 87 |
if payload:
|
| 88 |
print(f"\n>>> Payload: {payload}")
|
| 89 |
# Gọi API với stream=True
|
| 90 |
-
response = requests.post(
|
| 91 |
|
| 92 |
for chunk in response.iter_lines():
|
| 93 |
if counter == 0:
|
|
@@ -125,6 +139,9 @@ with gr.Blocks(
|
|
| 125 |
gr.HTML(title)
|
| 126 |
|
| 127 |
with gr.Column(elem_id="col_container", visible=True) as main_block:
|
|
|
|
|
|
|
|
|
|
| 128 |
chatbot = gr.Chatbot(elem_id='chatbot')
|
| 129 |
inputs = gr.Textbox(placeholder="Hi there!", label="Type an input and press Enter")
|
| 130 |
state = gr.State([])
|
|
@@ -145,10 +162,10 @@ with gr.Blocks(
|
|
| 145 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
| 146 |
|
| 147 |
inputs.submit(reset_textbox, [], [inputs, b1], queue=False)
|
| 148 |
-
inputs.submit(predict, [system_prompt, inputs, top_p, temperature, max_tokens, chat_counter, chatbot, state],
|
| 149 |
[chatbot, state, chat_counter, server_status_code, inputs, b1])
|
| 150 |
b1.click(reset_textbox, [], [inputs, b1], queue=False)
|
| 151 |
-
b1.click(predict, [system_prompt, inputs, top_p, temperature, max_tokens, chat_counter, chatbot, state],
|
| 152 |
[chatbot, state, chat_counter, server_status_code, inputs, b1])
|
| 153 |
|
| 154 |
demo.queue(max_size=10, default_concurrency_limit=NUM_THREADS, api_open=False).launch(share=False)
|
|
|
|
| 5 |
import requests
|
| 6 |
import random
|
| 7 |
|
| 8 |
+
API_URL = ""
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
LA_SERVICE_URL_v1 = "http://bore.testsprep.online:8082/v1/chat/completions"
|
| 12 |
+
LA_SERVICE_URL_v2 = "http://bore.testsprep.online:8083/v1/chat/completions"
|
| 13 |
+
LA_SERVICE_URL_v3 = "http://bore.testsprep.online:8084/v1/chat/completions"
|
| 14 |
+
LA_SERVICE_URL_v4 = "http://bore.testsprep.online:8085/v1/chat/completions"
|
| 15 |
+
|
| 16 |
+
MODEL2SERVICE = {
|
| 17 |
+
'LA-llama-3.1-7b-16k-sft-awq': LA_SERVICE_URL_v1,
|
| 18 |
+
'LA-storm-llama-3.1-7b-16k-sft-awq': LA_SERVICE_URL_v2,
|
| 19 |
+
'LA-cohere-aya-expanse-8b-16k-sft-awq': LA_SERVICE_URL_v3,
|
| 20 |
+
'LA-qwen2.5-7b-16k-sft-awq': LA_SERVICE_URL_v4,
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
DISABLED = os.getenv("DISABLED") == 'True'
|
| 24 |
BEARER_TOKEN = "Prep@123"
|
| 25 |
NUM_THREADS = 16
|
|
|
|
| 36 |
sys.tracebacklimit = 0
|
| 37 |
|
| 38 |
|
| 39 |
+
def predict(model_selector, system_prompt, inputs, top_p, temperature, max_tokens, chat_counter, chatbot, history, request: gr.Request):
|
| 40 |
messages = [{"role": "system", "content": system_prompt}] if system_prompt else []
|
| 41 |
|
| 42 |
headers = {
|
|
|
|
| 101 |
if payload:
|
| 102 |
print(f"\n>>> Payload: {payload}")
|
| 103 |
# Gọi API với stream=True
|
| 104 |
+
response = requests.post(MODEL2SERVICE[model_selector], headers=headers, json=payload, stream=True)
|
| 105 |
|
| 106 |
for chunk in response.iter_lines():
|
| 107 |
if counter == 0:
|
|
|
|
| 139 |
gr.HTML(title)
|
| 140 |
|
| 141 |
with gr.Column(elem_id="col_container", visible=True) as main_block:
|
| 142 |
+
|
| 143 |
+
model_selector = gr.Dropdown(choices=list(MODEL2SERVICE.keys()), label="Select Model", value=list(MODEL2SERVICE.keys())[0])
|
| 144 |
+
|
| 145 |
chatbot = gr.Chatbot(elem_id='chatbot')
|
| 146 |
inputs = gr.Textbox(placeholder="Hi there!", label="Type an input and press Enter")
|
| 147 |
state = gr.State([])
|
|
|
|
| 162 |
chat_counter = gr.Number(value=0, visible=False, precision=0)
|
| 163 |
|
| 164 |
inputs.submit(reset_textbox, [], [inputs, b1], queue=False)
|
| 165 |
+
inputs.submit(predict, [model_selector, system_prompt, inputs, top_p, temperature, max_tokens, chat_counter, chatbot, state],
|
| 166 |
[chatbot, state, chat_counter, server_status_code, inputs, b1])
|
| 167 |
b1.click(reset_textbox, [], [inputs, b1], queue=False)
|
| 168 |
+
b1.click(predict, [model_selector, system_prompt, inputs, top_p, temperature, max_tokens, chat_counter, chatbot, state],
|
| 169 |
[chatbot, state, chat_counter, server_status_code, inputs, b1])
|
| 170 |
|
| 171 |
demo.queue(max_size=10, default_concurrency_limit=NUM_THREADS, api_open=False).launch(share=False)
|