Update app.py
Browse files
app.py
CHANGED
@@ -1,57 +1,8 @@
|
|
1 |
-
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
history: list[tuple[str, str]],
|
10 |
-
system_message,
|
11 |
-
max_tokens,
|
12 |
-
temperature,
|
13 |
-
top_p,
|
14 |
-
):
|
15 |
-
messages = [{"role": "system", "content": system_message}]
|
16 |
-
|
17 |
-
for val in history:
|
18 |
-
if val[0]:
|
19 |
-
messages.append({"role": "user", "content": val[0]})
|
20 |
-
if val[1]:
|
21 |
-
messages.append({"role": "assistant", "content": val[1]})
|
22 |
-
|
23 |
-
messages.append({"role": "user", "content": message})
|
24 |
-
|
25 |
-
response = ""
|
26 |
-
|
27 |
-
for message in client.chat_completion(
|
28 |
-
messages,
|
29 |
-
max_tokens=max_tokens,
|
30 |
-
stream=True,
|
31 |
-
temperature=temperature,
|
32 |
-
top_p=top_p,
|
33 |
-
):
|
34 |
-
token = message.choices[0].delta.content
|
35 |
-
|
36 |
-
response += token
|
37 |
-
yield response
|
38 |
-
|
39 |
-
# Konfiguracja interfejsu Gradio
|
40 |
-
demo = gr.ChatInterface(
|
41 |
-
respond,
|
42 |
-
additional_inputs=[
|
43 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
44 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
45 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
46 |
-
gr.Slider(
|
47 |
-
minimum=0.1,
|
48 |
-
maximum=1.0,
|
49 |
-
value=0.95,
|
50 |
-
step=0.05,
|
51 |
-
label="Top-p (nucleus sampling)",
|
52 |
-
),
|
53 |
-
],
|
54 |
-
)
|
55 |
-
|
56 |
-
if __name__ == "__main__":
|
57 |
-
demo.launch()
|
|
|
1 |
+
# Use a pipeline as a high-level helper
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
messages = [
|
5 |
+
{"role": "user", "content": "Who are you?"},
|
6 |
+
]
|
7 |
+
pipe = pipeline("text-generation", model="microsoft/Phi-3.5-MoE-instruct", trust_remote_code=True)
|
8 |
+
pipe(messages)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|