Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,9 +4,16 @@ from huggingface_hub import InferenceClient
|
|
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 |
-
|
8 |
-
client = InferenceClient("gpt2") # Ganti dengan model yang valid di HuggingFace
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def respond(
|
12 |
message,
|
@@ -16,36 +23,36 @@ def respond(
|
|
16 |
temperature,
|
17 |
top_p,
|
18 |
):
|
19 |
-
#
|
20 |
system_message = "Hai, apa ada yang bisa saya bantu?"
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
|
31 |
-
if message.lower() == "siapa riswan?":
|
32 |
-
messages.append({"role": "user", "content": "Siapa Riswan dan apa yang dia buat?"})
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
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
|
|
|
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 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
|
8 |
|
9 |
+
# Jawaban yang telah disediakan untuk pertanyaan tentang Riswan
|
10 |
+
faq_data = {
|
11 |
+
"siapa riswan?": "Riswan adalah pembuat sistem ini, seorang pengembang yang bekerja dengan teknologi terbaru untuk membangun aplikasi AI.",
|
12 |
+
"apa pekerjaan riswan?": "Riswan adalah seorang pengembang perangkat lunak dan ilmuwan data.",
|
13 |
+
"di mana riswan bekerja?": "Riswan bekerja di perusahaan teknologi besar yang berfokus pada pengembangan AI dan pemrograman.",
|
14 |
+
"apa riswan suka coding?": "Ya, Riswan sangat suka coding dan selalu belajar teknologi terbaru.",
|
15 |
+
"apa projek terbesar riswan?": "Projek terbesar Riswan adalah pengembangan platform berbasis AI yang membantu berbagai perusahaan mengotomatiskan proses bisnis mereka.",
|
16 |
+
}
|
17 |
|
18 |
def respond(
|
19 |
message,
|
|
|
23 |
temperature,
|
24 |
top_p,
|
25 |
):
|
26 |
+
# Pesan sistem awal dalam bahasa Indonesia
|
27 |
system_message = "Hai, apa ada yang bisa saya bantu?"
|
28 |
|
29 |
+
# Mengecek apakah pertanyaan tentang Riswan ada dalam FAQ
|
30 |
+
if message.lower() in faq_data:
|
31 |
+
response = faq_data[message.lower()]
|
32 |
+
else:
|
33 |
+
# Jika tidak ada, sistem melanjutkan dengan API untuk memberikan jawaban
|
34 |
+
messages = [{"role": "system", "content": system_message}]
|
35 |
|
36 |
+
for val in history:
|
37 |
+
if val[0]:
|
38 |
+
messages.append({"role": "user", "content": val[0]})
|
39 |
+
if val[1]:
|
40 |
+
messages.append({"role": "assistant", "content": val[1]})
|
41 |
|
42 |
+
messages.append({"role": "user", "content": message})
|
|
|
|
|
43 |
|
44 |
+
response = ""
|
45 |
+
for message in client.chat_completion(
|
46 |
+
messages,
|
47 |
+
max_tokens=max_tokens,
|
48 |
+
stream=True,
|
49 |
+
temperature=temperature,
|
50 |
+
top_p=top_p,
|
51 |
+
):
|
52 |
+
token = message.choices[0].delta.content
|
53 |
+
response += token
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
yield response
|
56 |
|
57 |
"""
|
58 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|