Doppler999
commited on
Commit
·
0bbac0a
1
Parent(s):
7ea82ac
Add Gradio interface for chatbot
Browse files- app.py +9 -26
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -6,15 +6,7 @@ For more information on `huggingface_hub` Inference API support, please check th
|
|
| 6 |
"""
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
| 9 |
-
|
| 10 |
-
def respond(
|
| 11 |
-
message,
|
| 12 |
-
history: list[tuple[str, str]],
|
| 13 |
-
system_message,
|
| 14 |
-
max_tokens,
|
| 15 |
-
temperature,
|
| 16 |
-
top_p,
|
| 17 |
-
):
|
| 18 |
messages = [{"role": "system", "content": system_message}]
|
| 19 |
|
| 20 |
for val in history:
|
|
@@ -35,29 +27,20 @@ def respond(
|
|
| 35 |
top_p=top_p,
|
| 36 |
):
|
| 37 |
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
response += token
|
| 40 |
yield response
|
| 41 |
|
| 42 |
-
"""
|
| 43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 44 |
-
"""
|
| 45 |
demo = gr.ChatInterface(
|
| 46 |
-
respond,
|
| 47 |
additional_inputs=[
|
| 48 |
-
gr.Textbox(
|
| 49 |
-
gr.Slider(
|
| 50 |
-
gr.Slider(
|
| 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()
|
|
|
|
| 6 |
"""
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
| 9 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
messages = [{"role": "system", "content": system_message}]
|
| 11 |
|
| 12 |
for val in history:
|
|
|
|
| 27 |
top_p=top_p,
|
| 28 |
):
|
| 29 |
token = message.choices[0].delta.content
|
|
|
|
| 30 |
response += token
|
| 31 |
yield response
|
| 32 |
|
|
|
|
|
|
|
|
|
|
| 33 |
demo = gr.ChatInterface(
|
| 34 |
+
fn=respond,
|
| 35 |
additional_inputs=[
|
| 36 |
+
gr.Textbox(lines=2, label="System Message", placeholder="You are a helpful assistant."),
|
| 37 |
+
gr.Slider(0, 1024, value=256, step=1, label="Max Tokens"),
|
| 38 |
+
gr.Slider(0, 1, value=0.7, step=0.01, label="Temperature"),
|
| 39 |
+
gr.Slider(0, 1, value=0.9, step=0.01, label="Top-p")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
],
|
| 41 |
+
title="Chat with Zephyr-7b",
|
| 42 |
+
description="Chatbot powered by Hugging Face Inference API."
|
| 43 |
)
|
| 44 |
|
| 45 |
+
demo.launch(share=True)
|
| 46 |
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
huggingface_hub==0.22.2
|
|
|
|
|
|
| 1 |
+
huggingface_hub==0.22.2
|
| 2 |
+
gradio
|