Spaces:
Sleeping
Sleeping
salomonsky
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,26 @@
|
|
1 |
-
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
system_prompt = "Deber谩s proporcinar c贸digo limpio, resumido, investigando cada l铆nea en internet en foros, revisa stackoverflow.com para consultas, elimina comentarios siempre, concatena el funcionamiento de los bloques y bibliotecas, y esquematiza el funcionamiento global del c贸digo. Preve茅 posibles errores y complementa al final con una tabla explicando el funcionamiento, propon alternativas de bibliotecas para solucionar errores, siempre consulta internet para posibles resoluciones."
|
6 |
system_prompt_sent = False
|
7 |
|
8 |
def format_prompt(message, history):
|
9 |
global system_prompt_sent
|
10 |
-
prompt = "
|
11 |
|
12 |
-
if not any(f"[INST] {system_prompt}
|
13 |
-
prompt += f"
|
14 |
system_prompt_sent = True
|
15 |
|
16 |
for user_prompt, bot_response in history:
|
17 |
-
prompt += f"[INST] {user_prompt} [
|
18 |
-
prompt +=
|
19 |
|
20 |
-
prompt += f"[INST] {message}
|
21 |
return prompt
|
22 |
|
23 |
-
def generate(
|
24 |
-
prompt, history, temperature=0.9, max_new_tokens=4096, top_p=0.95, repetition_penalty=1.0,
|
25 |
-
):
|
26 |
-
global system_prompt_sent
|
27 |
temperature = float(temperature)
|
28 |
if temperature < 1e-2:
|
29 |
temperature = 1e-2
|
@@ -39,7 +36,7 @@ def generate(
|
|
39 |
)
|
40 |
|
41 |
formatted_prompt = format_prompt(prompt, history)
|
42 |
-
|
43 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
44 |
output = ""
|
45 |
|
@@ -49,8 +46,15 @@ def generate(
|
|
49 |
|
50 |
return output
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
chat_interface = gr.ChatInterface(
|
53 |
-
fn=
|
54 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=False, likeable=False, layout="vertical", height=900),
|
55 |
concurrency_limit=9,
|
56 |
theme="soft",
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
import concurrent.futures
|
4 |
|
5 |
+
system_prompt = ""
|
|
|
6 |
system_prompt_sent = False
|
7 |
|
8 |
def format_prompt(message, history):
|
9 |
global system_prompt_sent
|
10 |
+
prompt = "[INST] "
|
11 |
|
12 |
+
if not any(f"[INST] {system_prompt} " in user_prompt for user_prompt, _ in history):
|
13 |
+
prompt += f"{system_prompt} "
|
14 |
system_prompt_sent = True
|
15 |
|
16 |
for user_prompt, bot_response in history:
|
17 |
+
prompt += f"[INST] {user_prompt} [{bot_response}]"
|
18 |
+
prompt += " "
|
19 |
|
20 |
+
prompt += f"[INST] {message} "
|
21 |
return prompt
|
22 |
|
23 |
+
def generate(prompt, history, temperature=0.9, max_new_tokens=4096, top_p=0.95, repetition_penalty=1.0):
|
|
|
|
|
|
|
24 |
temperature = float(temperature)
|
25 |
if temperature < 1e-2:
|
26 |
temperature = 1e-2
|
|
|
36 |
)
|
37 |
|
38 |
formatted_prompt = format_prompt(prompt, history)
|
39 |
+
|
40 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
41 |
output = ""
|
42 |
|
|
|
46 |
|
47 |
return output
|
48 |
|
49 |
+
def run_chatbot(prompt, history, temperature, max_new_tokens, top_p, repetition_penalty):
|
50 |
+
global client
|
51 |
+
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
52 |
+
with concurrent.futures.ProcessPoolExecutor() as executor:
|
53 |
+
result = executor.submit(generate, prompt, history, temperature, max_new_tokens, top_p, repetition_penalty)
|
54 |
+
return result
|
55 |
+
|
56 |
chat_interface = gr.ChatInterface(
|
57 |
+
fn=run_chatbot,
|
58 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=False, likeable=False, layout="vertical", height=900),
|
59 |
concurrency_limit=9,
|
60 |
theme="soft",
|