Spaces:
Sleeping
Sleeping
updated gradio interface
Browse files
app.py
CHANGED
|
@@ -92,18 +92,10 @@ def bot(history,temperature, max_new_tokens, top_p,top_k):
|
|
| 92 |
do_sample=True
|
| 93 |
)
|
| 94 |
|
| 95 |
-
#
|
| 96 |
response = tokenizer.batch_decode(response, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 97 |
-
#response = response.split("### Tanggapan:")
|
| 98 |
-
#response = response[1].strip() if len(response) > 1 else ""
|
| 99 |
sections = response.split("###")
|
| 100 |
-
|
| 101 |
-
# Ambil potongan yang berisi "Tanggapan" yang pertama
|
| 102 |
response = sections[3]
|
| 103 |
-
|
| 104 |
-
#return response.split("Tanggapan:")[1].strip()
|
| 105 |
-
#history[-1] = response.split("Tanggapan:")[1].strip()
|
| 106 |
-
#return history
|
| 107 |
response=response.split("Tanggapan:")[1].strip()
|
| 108 |
history[-1][1] = response
|
| 109 |
return history
|
|
@@ -114,30 +106,32 @@ with gr.Blocks() as demo:
|
|
| 114 |
"""# ChatDoctor - PolyLM 1.7b 🩺
|
| 115 |
|
| 116 |
A [ChatDoctor - PolyLM 1.7b](https://huggingface.co/fadliaulawi/polylm-1.7b-finetuned) demo.
|
| 117 |
-
From the [PolyLM 1.7b](https://huggingface.co/DAMO-NLP-MT/polylm-1.7b) model and finetuned on [ChatDoctor](https://github.com/Kent0n-Li/ChatDoctor) dataset.
|
| 118 |
|
| 119 |
"""
|
| 120 |
)
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
submit = gr.Button("Submit")
|
| 129 |
-
clear = gr.Button("Clear")
|
| 130 |
-
with gr.Column():
|
| 131 |
-
chatbot = gr.Chatbot()
|
| 132 |
-
examples = gr.Examples(examples=["Dokter, aku merasa sangat depresi akhir-akhir ini dan juga mengalami perubahan suhu tubuhku.",
|
| 133 |
-
"Dokter, aku mengalami kelelahan akhir-akhir ini.",
|
| 134 |
-
"Dokter, aku merasa pusing, lemah dan sakit dada tajam akhir-akhir ini.",
|
| 135 |
"Dokter, saya sudah beberapa minggu mengalami suara serak dan tidak kunjung membaik meski sudah minum obat. Apa masalahnya?"
|
| 136 |
],inputs=[msg])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
-
|
| 139 |
bot, [chatbot,temperature,max_length,top_p,top_k], chatbot
|
| 140 |
)
|
| 141 |
-
|
| 142 |
|
| 143 |
demo.queue(concurrency_count=100).launch()
|
|
|
|
| 92 |
do_sample=True
|
| 93 |
)
|
| 94 |
|
| 95 |
+
# clean up response before returning
|
| 96 |
response = tokenizer.batch_decode(response, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
|
|
|
|
|
|
| 97 |
sections = response.split("###")
|
|
|
|
|
|
|
| 98 |
response = sections[3]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
response=response.split("Tanggapan:")[1].strip()
|
| 100 |
history[-1][1] = response
|
| 101 |
return history
|
|
|
|
| 106 |
"""# ChatDoctor - PolyLM 1.7b 🩺
|
| 107 |
|
| 108 |
A [ChatDoctor - PolyLM 1.7b](https://huggingface.co/fadliaulawi/polylm-1.7b-finetuned) demo.
|
| 109 |
+
From the [PolyLM 1.7b](https://huggingface.co/DAMO-NLP-MT/polylm-1.7b) model and finetuned on the Indonesian translation of [ChatDoctor](https://github.com/Kent0n-Li/ChatDoctor) dataset.
|
| 110 |
|
| 111 |
"""
|
| 112 |
)
|
| 113 |
+
|
| 114 |
+
chatbot = gr.Chatbot()
|
| 115 |
+
msg = gr.Textbox()
|
| 116 |
+
submit = gr.Button("Submit")
|
| 117 |
+
clear = gr.Button("Clear")
|
| 118 |
+
examples = gr.Examples(examples=["Dokter, aku mengalami kelelahan akhir-akhir ini.", "Dokter, aku merasa pusing, lemah dan sakit dada tajam akhir-akhir ini.",
|
| 119 |
+
"Dokter, aku merasa sangat depresi akhir-akhir ini dan juga mengalami perubahan suhu tubuhku.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
"Dokter, saya sudah beberapa minggu mengalami suara serak dan tidak kunjung membaik meski sudah minum obat. Apa masalahnya?"
|
| 121 |
],inputs=[msg])
|
| 122 |
+
|
| 123 |
+
gr.Markdown(
|
| 124 |
+
"""## Adjust the additional inputs:"""
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
temperature = gr.Slider(0, 5, value=0.8, step=0.1, label='Temperature',info="Controls randomness, higher values increase diversity.")
|
| 128 |
+
max_length = gr.Slider(0, 1024, value=50, step=1, label='Max Length',info="The maximum numbers of output's tokens.")
|
| 129 |
+
top_p = gr.Slider(0, 1, value=0.8, step=0.1, label='Top P',info="The cumulative probability cutoff for token selection. Lower values mean sampling from a smaller, more top-weighted nucleus.")
|
| 130 |
+
top_k = gr.Slider(0, 50, value=10, step=1, label='Top K',info="Sample from the k most likely next tokens at each step. Lower k focuses on higher probability tokens.")
|
| 131 |
|
| 132 |
+
submit.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 133 |
bot, [chatbot,temperature,max_length,top_p,top_k], chatbot
|
| 134 |
)
|
| 135 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 136 |
|
| 137 |
demo.queue(concurrency_count=100).launch()
|