Spaces:
Sleeping
Sleeping
push
Browse files
app.py
CHANGED
@@ -1,10 +1,15 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import InferenceClient
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
|
|
|
|
|
|
|
|
|
8 |
def respond(
|
9 |
message,
|
10 |
history: list[tuple[str, str]],
|
@@ -25,29 +30,24 @@ def respond(
|
|
25 |
|
26 |
response = ""
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
yield response
|
41 |
-
except Exception as e:
|
42 |
-
print(f"Error: {e}")
|
43 |
-
yield "Произошла ошибка при обработке вашего запроса."
|
44 |
-
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
48 |
-
gr.Textbox(value="
|
49 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="
|
50 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="
|
51 |
gr.Slider(
|
52 |
minimum=0.1,
|
53 |
maximum=1.0,
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import InferenceClient
|
4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
5 |
|
6 |
+
# Убедись, что токен загружен из переменной окружения или напрямую
|
7 |
+
HF_TOKEN = os.getenv("HUGGINGFACE_TOKEN") # Загрузка токена из .env
|
8 |
|
9 |
+
# Инициализация клиента
|
10 |
+
client = InferenceClient("sambanovasystems/SambaLingo-Russian-Chat", token=HF_TOKEN)
|
11 |
+
|
12 |
+
# Функция для ответа на сообщения
|
13 |
def respond(
|
14 |
message,
|
15 |
history: list[tuple[str, str]],
|
|
|
30 |
|
31 |
response = ""
|
32 |
|
33 |
+
for message in client.chat_completion(
|
34 |
+
messages,
|
35 |
+
max_tokens=max_tokens,
|
36 |
+
stream=True,
|
37 |
+
temperature=temperature,
|
38 |
+
top_p=top_p,
|
39 |
+
):
|
40 |
+
token = message.choices[0].delta.content
|
41 |
+
response += token
|
42 |
+
yield response
|
43 |
+
|
44 |
+
# Настройка интерфейса Gradio
|
|
|
|
|
|
|
|
|
|
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
48 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
49 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
50 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
51 |
gr.Slider(
|
52 |
minimum=0.1,
|
53 |
maximum=1.0,
|