scriptolip commited on
Commit
fd5c58c
·
verified ·
1 Parent(s): d6bd310

update 3 app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -53
app.py CHANGED
@@ -1,58 +1,17 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
 
4
- # Initialize the InferenceClient with the model
5
- client = InferenceClient("LLM360/K2-Chat")
6
 
7
- def respond(
8
- message,
9
- history: list[tuple[str, str]],
10
- system_message,
11
- max_tokens,
12
- temperature,
13
- top_p,
14
- ):
15
- # Prepare the messages for the model
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
- # Generate the response from the model
29
- for message in client.chat_completion(
30
- messages,
31
- max_tokens=max_tokens,
32
- stream=True,
33
- temperature=temperature,
34
- top_p=top_p,
35
- ):
36
- token = message.choices[0].delta.content
37
- response += token
38
- yield response
39
-
40
- # Create a Gradio ChatInterface
41
- demo = gr.ChatInterface(
42
- respond,
43
- additional_inputs=[
44
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
45
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
46
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
47
- gr.Slider(
48
- minimum=0.1,
49
- maximum=1.0,
50
- value=0.95,
51
- step=0.05,
52
- label="Top-p (nucleus sampling)",
53
- ),
54
- ],
55
- )
56
-
57
- if __name__ == "__main__":
58
- demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Загрузка модели
5
+ model = pipeline("conversational", model="LLM360/K2-Chat")
6
 
7
+ def chat(message, history):
8
+ history.append((message, ""))
9
+ response = model(history)
10
+ history[-1] = (message, response[0]['generated_text'])
11
+ return history, ""
 
 
 
 
 
12
 
13
+ # Создание интерфейса
14
+ iface = gr.ChatInterface(chat)
 
 
 
15
 
16
+ # Запуск интерфейса
17
+ iface.launch()