Spaces:
Sleeping
Sleeping
switched to 3B o1
Browse files
app.py
CHANGED
@@ -5,18 +5,20 @@ import spaces
|
|
5 |
"""
|
6 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
7 |
"""
|
8 |
-
client = InferenceClient("
|
9 |
|
10 |
@spaces.GPU
|
11 |
def respond(
|
12 |
message,
|
13 |
history: list[tuple[str, str]],
|
14 |
-
system_message,
|
15 |
max_tokens,
|
16 |
temperature,
|
17 |
top_p,
|
18 |
):
|
19 |
-
messages = [{"role": "system", "content": system_message}]
|
|
|
|
|
20 |
|
21 |
for val in history:
|
22 |
if val[0]:
|
@@ -27,17 +29,33 @@ def respond(
|
|
27 |
messages.append({"role": "user", "content": message})
|
28 |
|
29 |
response = ""
|
|
|
30 |
|
31 |
for message in client.chat_completion(
|
32 |
messages,
|
33 |
max_tokens=max_tokens,
|
34 |
stream=True,
|
35 |
-
temperature=temperature,
|
36 |
top_p=top_p,
|
|
|
|
|
37 |
):
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
-
response +=
|
|
|
41 |
yield response
|
42 |
|
43 |
|
@@ -46,12 +64,12 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
46 |
"""
|
47 |
demo = gr.ChatInterface(
|
48 |
respond,
|
49 |
-
title="LLama 3.2 MedIT
|
50 |
description="Built with Llama. Please note that this model is not a source of knowledge and is not intended to provide 100% accurate answers. If the model provides answers that are generally considered inappropriate, please contact me.",
|
51 |
additional_inputs=[
|
52 |
-
gr.Textbox(value="You are a helpful, smart, kind, and efficient AI assistant. You always fulfill the user's requests to the best of your ability. You always think and reflect before providing final answers in a step-by-step manner.", label="System message"),
|
53 |
-
gr.Slider(minimum=1, maximum=
|
54 |
-
gr.Slider(minimum=0.
|
55 |
gr.Slider(
|
56 |
minimum=0.1,
|
57 |
maximum=1.0,
|
|
|
5 |
"""
|
6 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
7 |
"""
|
8 |
+
client = InferenceClient("mkurman/llama-3.2-MEDIT-3B-o1")
|
9 |
|
10 |
@spaces.GPU
|
11 |
def respond(
|
12 |
message,
|
13 |
history: list[tuple[str, str]],
|
14 |
+
# system_message,
|
15 |
max_tokens,
|
16 |
temperature,
|
17 |
top_p,
|
18 |
):
|
19 |
+
# messages = [{"role": "system", "content": system_message}]
|
20 |
+
|
21 |
+
messages = []
|
22 |
|
23 |
for val in history:
|
24 |
if val[0]:
|
|
|
29 |
messages.append({"role": "user", "content": message})
|
30 |
|
31 |
response = ""
|
32 |
+
counter = 0
|
33 |
|
34 |
for message in client.chat_completion(
|
35 |
messages,
|
36 |
max_tokens=max_tokens,
|
37 |
stream=True,
|
38 |
+
temperature=temperature if temperature > 0.0 else None,
|
39 |
top_p=top_p,
|
40 |
+
logprobs=True,
|
41 |
+
stop=['</Output>']
|
42 |
):
|
43 |
+
text = message.choices[0].delta.content
|
44 |
+
|
45 |
+
token = message.choices[0].logprobs.content[0].token
|
46 |
+
|
47 |
+
if token in ['<Thought>', '<|python_tag|>']:
|
48 |
+
text = '## Thinking:\n\n' + text
|
49 |
+
|
50 |
+
if token == '<Output>' and counter > 0:
|
51 |
+
text = '## Output:\n\n' + text
|
52 |
+
|
53 |
+
if token == '</Output>':
|
54 |
+
yield None
|
55 |
+
break
|
56 |
|
57 |
+
response += text
|
58 |
+
counter += 1
|
59 |
yield response
|
60 |
|
61 |
|
|
|
64 |
"""
|
65 |
demo = gr.ChatInterface(
|
66 |
respond,
|
67 |
+
title="LLama 3.2 MedIT 3B o1",
|
68 |
description="Built with Llama. Please note that this model is not a source of knowledge and is not intended to provide 100% accurate answers. If the model provides answers that are generally considered inappropriate, please contact me.",
|
69 |
additional_inputs=[
|
70 |
+
# gr.Textbox(value="You are a helpful, smart, kind, and efficient AI assistant. You always fulfill the user's requests to the best of your ability. You always think and reflect before providing final answers in a step-by-step manner.", label="System message"),
|
71 |
+
gr.Slider(minimum=1, maximum=4096, value=2048, step=1, label="Max new tokens"),
|
72 |
+
gr.Slider(minimum=0.0, maximum=4.0, value=0.0, step=0.1, label="Temperature"),
|
73 |
gr.Slider(
|
74 |
minimum=0.1,
|
75 |
maximum=1.0,
|