Spaces:
Sleeping
Sleeping
mini
Browse files- app.py +50 -9
- requirements.txt +2 -1
app.py
CHANGED
@@ -2,14 +2,55 @@ import os
|
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
5 |
-
# Получаем токен из окружения
|
6 |
-
|
7 |
-
client = InferenceClient("sambanovasystems/SambaLingo-Russian-Chat", token=hf_token)
|
8 |
|
9 |
-
def respond(
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
5 |
+
# Получаем токен из переменных окружения
|
6 |
+
client = InferenceClient(os.getenv("HUGGINGFACE_TOKEN"))
|
|
|
7 |
|
8 |
+
def respond(
|
9 |
+
message,
|
10 |
+
history: list[tuple[str, str]],
|
11 |
+
system_message,
|
12 |
+
max_tokens,
|
13 |
+
temperature,
|
14 |
+
top_p,
|
15 |
+
):
|
16 |
+
messages = [{"role": "system", "content": system_message}]
|
17 |
|
18 |
+
for val in history:
|
19 |
+
if val[0]:
|
20 |
+
messages.append({"role": "user", "content": val[0]})
|
21 |
+
if val[1]:
|
22 |
+
messages.append({"role": "assistant", "content": val[1]})
|
23 |
+
|
24 |
+
messages.append({"role": "user", "content": message})
|
25 |
+
|
26 |
+
response = ""
|
27 |
+
|
28 |
+
for message in client.chat_completion(
|
29 |
+
messages,
|
30 |
+
max_tokens=max_tokens,
|
31 |
+
stream=True,
|
32 |
+
temperature=temperature,
|
33 |
+
top_p=top_p,
|
34 |
+
):
|
35 |
+
token = message.choices[0].delta.content
|
36 |
+
response += token
|
37 |
+
yield response
|
38 |
+
|
39 |
+
demo = gr.ChatInterface(
|
40 |
+
respond,
|
41 |
+
additional_inputs=[
|
42 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
43 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
44 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
45 |
+
gr.Slider(
|
46 |
+
minimum=0.1,
|
47 |
+
maximum=1.0,
|
48 |
+
value=0.95,
|
49 |
+
step=0.05,
|
50 |
+
label="Top-p (nucleus sampling)",
|
51 |
+
),
|
52 |
+
],
|
53 |
+
)
|
54 |
+
|
55 |
+
if __name__ == "__main__":
|
56 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
huggingface_hub==0.22.2
|
|
|
|
1 |
+
huggingface_hub==0.22.2
|
2 |
+
minijinja
|