Riswan-Nopiyar commited on
Commit
7a9b944
·
verified ·
1 Parent(s): 1234988

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -70
app.py CHANGED
@@ -1,71 +1,32 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- # Menggunakan model Gemini yang tersedia di HuggingFace
8
- client = InferenceClient("google/gemini-xx") # Gantilah dengan nama model Gemini yang tepat
9
-
10
-
11
- def respond(
12
- message,
13
- history: list[tuple[str, str]],
14
- system_message,
15
- max_tokens,
16
- temperature,
17
- top_p,
18
- ):
19
- # Set system message to greet in Indonesian
20
- system_message = "Hai, apa ada yang bisa saya bantu?"
21
-
22
- messages = [{"role": "system", "content": system_message}]
23
-
24
- for val in history:
25
- if val[0]:
26
- messages.append({"role": "user", "content": val[0]})
27
- if val[1]:
28
- messages.append({"role": "assistant", "content": val[1]})
29
-
30
- # Menambahkan pertanyaan tentang Riswan
31
- if message.lower() == "siapa riswan?":
32
- messages.append({"role": "user", "content": "Siapa Riswan dan apa yang dia buat?"})
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()