Update app.py
Browse files
app.py
CHANGED
@@ -1,71 +1,32 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
#
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
messages.append({"role": "user", "content": message})
|
35 |
-
|
36 |
-
response = ""
|
37 |
-
|
38 |
-
for message in client.chat_completion(
|
39 |
-
messages,
|
40 |
-
max_tokens=max_tokens,
|
41 |
-
stream=True,
|
42 |
-
temperature=temperature,
|
43 |
-
top_p=top_p,
|
44 |
-
):
|
45 |
-
token = message.choices[0].delta.content
|
46 |
-
response += token
|
47 |
-
yield response
|
48 |
-
|
49 |
-
|
50 |
-
"""
|
51 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
52 |
-
"""
|
53 |
-
demo = gr.ChatInterface(
|
54 |
-
respond,
|
55 |
-
additional_inputs=[
|
56 |
-
gr.Textbox(value="Anda adalah chatbot yang ramah.", label="Pesan Sistem"),
|
57 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max token baru"),
|
58 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperatur"),
|
59 |
-
gr.Slider(
|
60 |
-
minimum=0.1,
|
61 |
-
maximum=1.0,
|
62 |
-
value=0.95,
|
63 |
-
step=0.05,
|
64 |
-
label="Top-p (nukleus sampling)",
|
65 |
-
),
|
66 |
-
],
|
67 |
-
)
|
68 |
-
|
69 |
-
|
70 |
-
if __name__ == "__main__":
|
71 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from functions import random_plot, add_message, chat_mem, print_like_dislike
|
3 |
+
|
4 |
+
# Ambil pesan awal dari chat_mem
|
5 |
+
initial_messages = [(None, "Selamat datang di chatbot Nopiyar.my.id! Ada yang bisa saya bantu?")]
|
6 |
+
fig = random_plot()
|
7 |
+
|
8 |
+
# Membuat antarmuka Gradio
|
9 |
+
with gr.Blocks(fill_height=True, css="footer {visibility: hidden}") as demo:
|
10 |
+
gr.HTML("<div style='text-align: center;'><h2>Chat bot Nopiyar.my.id</h2></div>") # Menambahkan judul di sini dengan CSS untuk memposisikan di tengah
|
11 |
+
chatbot = gr.Chatbot(
|
12 |
+
label="NPR",
|
13 |
+
elem_id="chatbot",
|
14 |
+
bubble_full_width=True,
|
15 |
+
scale=1,
|
16 |
+
avatar_images=(None, "https://iili.io/d5tk44a.md.png"),
|
17 |
+
placeholder="Masukkan pesan...",
|
18 |
+
render_markdown=True,
|
19 |
+
sanitize_html=True,
|
20 |
+
show_copy_button=True,
|
21 |
+
value=initial_messages
|
22 |
+
)
|
23 |
+
|
24 |
+
chat_input = gr.Textbox(interactive=True, placeholder="Masukkan pesan...", show_label=False)
|
25 |
+
|
26 |
+
chat_msg = chat_input.submit(add_message, [chatbot, chat_input], [chatbot, chat_input])
|
27 |
+
bot_msg = chat_msg.then(chat_mem, inputs=[chat_input, chatbot], outputs=[chat_input, chatbot], api_name="bot_response")
|
28 |
+
bot_msg.then(lambda: gr.Textbox(interactive=True), None, [chat_input])
|
29 |
+
|
30 |
+
chatbot.like(print_like_dislike, None, None) # Menjaga fitur like (tetap bisa digunakan jika perlu)
|
31 |
+
|
32 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|