Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,34 @@
|
|
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 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
|
20 |
for val in history:
|
@@ -26,38 +40,46 @@ def respond(
|
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
response = ""
|
|
|
29 |
|
30 |
-
for message in client.chat_completion(
|
31 |
-
messages,
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
token = message.choices[0].delta.content
|
38 |
-
|
39 |
response += token
|
40 |
yield response
|
41 |
|
42 |
-
""
|
43 |
-
|
44 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
48 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
49 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
50 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
51 |
-
gr.Slider(
|
52 |
-
minimum=0.1,
|
53 |
-
maximum=1.0,
|
54 |
-
value=0.95,
|
55 |
-
step=0.05,
|
56 |
-
label="Top-p (nucleus sampling)",
|
57 |
-
),
|
58 |
],
|
|
|
|
|
59 |
)
|
60 |
|
61 |
-
|
62 |
if __name__ == "__main__":
|
63 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
|
|
|
|
|
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
6 |
+
# Function to convert days to score
|
7 |
+
def days_to_score(days):
|
8 |
+
if days == 0:
|
9 |
+
return 0
|
10 |
+
elif days == 1:
|
11 |
+
return 1
|
12 |
+
elif 2 <= days <= 3:
|
13 |
+
return 2
|
14 |
+
elif 4 <= days <= 7:
|
15 |
+
return 3
|
16 |
+
else:
|
17 |
+
return 0 # This case should not happen as the input sliders are restricted
|
18 |
|
19 |
+
# Function to diagnose GERD based on input days
|
20 |
+
def diagnose_gerd_responses(responses):
|
21 |
+
scores = [days_to_score(d) for d in responses]
|
22 |
+
total_score = sum(scores)
|
23 |
+
if total_score <= 7:
|
24 |
+
diagnosis = "Kemungkinan Anda tidak menderita GERD."
|
25 |
+
elif 8 <= total_score <= 18:
|
26 |
+
diagnosis = "Kemungkinan Anda menderita GERD. Konsultasikan dengan penyedia layanan kesehatan untuk evaluasi lebih lanjut."
|
27 |
+
else:
|
28 |
+
diagnosis = "Skor di luar jangkauan. Pastikan Anda memasukkan nilai dengan benar."
|
29 |
+
return diagnosis
|
30 |
+
|
31 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
32 |
messages = [{"role": "system", "content": system_message}]
|
33 |
|
34 |
for val in history:
|
|
|
40 |
messages.append({"role": "user", "content": message})
|
41 |
|
42 |
response = ""
|
43 |
+
user_responses = []
|
44 |
|
45 |
+
for message in client.chat_completion(messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p):
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
token = message.choices[0].delta.content
|
|
|
47 |
response += token
|
48 |
yield response
|
49 |
|
50 |
+
if "nyeri ulu hati" in message:
|
51 |
+
user_responses.append(int(message))
|
52 |
+
response = "Berapa hari dalam 7 hari terakhir Anda mengalami nyeri ulu hati?"
|
53 |
+
elif "regurgitasi" in message:
|
54 |
+
user_responses.append(int(message))
|
55 |
+
response = "Berapa hari dalam 7 hari terakhir Anda mengalami regurgitasi?"
|
56 |
+
elif "mual" in message:
|
57 |
+
user_responses.append(int(message))
|
58 |
+
response = "Berapa hari dalam 7 hari terakhir Anda mengalami mual?"
|
59 |
+
elif "sulit tidur" in message:
|
60 |
+
user_responses.append(int(message))
|
61 |
+
response = "Berapa hari dalam 7 hari terakhir Anda mengalami kesulitan tidur karena nyeri ulu hati?"
|
62 |
+
elif "minum obat" in message:
|
63 |
+
user_responses.append(int(message))
|
64 |
+
response = "Berapa hari dalam 7 hari terakhir Anda minum obat tambahan untuk nyeri ulu hati?"
|
65 |
+
|
66 |
+
if len(user_responses) == 6:
|
67 |
+
diagnosis = diagnose_gerd_responses(user_responses)
|
68 |
+
response = diagnosis
|
69 |
+
|
70 |
+
yield response
|
71 |
+
|
72 |
demo = gr.ChatInterface(
|
73 |
respond,
|
74 |
additional_inputs=[
|
75 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
76 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
77 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
78 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
],
|
80 |
+
title="Nexus-Gerd-Bot",
|
81 |
+
description="Chat dengan Nexus-Gerd-Bot untuk menilai kemungkinan GERD berdasarkan gejala yang Anda alami dalam 7 hari terakhir."
|
82 |
)
|
83 |
|
|
|
84 |
if __name__ == "__main__":
|
85 |
demo.launch()
|