Update app.py
Browse filesadded instruction
app.py
CHANGED
|
@@ -1,11 +1,7 @@
|
|
| 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 |
def respond(
|
| 11 |
message,
|
|
@@ -17,16 +13,15 @@ def respond(
|
|
| 17 |
):
|
| 18 |
messages = [{"role": "system", "content": system_message}]
|
| 19 |
|
| 20 |
-
for
|
| 21 |
-
if
|
| 22 |
-
messages.append({"role": "user", "content":
|
| 23 |
-
if
|
| 24 |
-
messages.append({"role": "assistant", "content":
|
| 25 |
|
| 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,
|
|
@@ -35,30 +30,44 @@ 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 |
-
"""
|
| 44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 45 |
-
"""
|
| 46 |
demo = gr.ChatInterface(
|
| 47 |
respond,
|
| 48 |
additional_inputs=[
|
| 49 |
-
gr.Textbox(
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
gr.Slider(
|
| 53 |
minimum=0.1,
|
| 54 |
maximum=1.0,
|
| 55 |
value=0.95,
|
| 56 |
step=0.05,
|
| 57 |
label="Top-p (nucleus sampling)",
|
|
|
|
| 58 |
),
|
| 59 |
],
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
| 63 |
if __name__ == "__main__":
|
| 64 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
client = InferenceClient("meta-llama/Llama-3.3-70B-Instruct")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def respond(
|
| 7 |
message,
|
|
|
|
| 13 |
):
|
| 14 |
messages = [{"role": "system", "content": system_message}]
|
| 15 |
|
| 16 |
+
for user_text, assistant_text in history:
|
| 17 |
+
if user_text:
|
| 18 |
+
messages.append({"role": "user", "content": user_text})
|
| 19 |
+
if assistant_text:
|
| 20 |
+
messages.append({"role": "assistant", "content": assistant_text})
|
| 21 |
|
| 22 |
messages.append({"role": "user", "content": message})
|
| 23 |
|
| 24 |
response = ""
|
|
|
|
| 25 |
for message in client.chat_completion(
|
| 26 |
messages,
|
| 27 |
max_tokens=max_tokens,
|
|
|
|
| 30 |
top_p=top_p,
|
| 31 |
):
|
| 32 |
token = message.choices[0].delta.content
|
|
|
|
| 33 |
response += token
|
| 34 |
yield response
|
| 35 |
|
| 36 |
+
# The additional_inputs are now hidden by setting visible=False.
|
|
|
|
|
|
|
|
|
|
| 37 |
demo = gr.ChatInterface(
|
| 38 |
respond,
|
| 39 |
additional_inputs=[
|
| 40 |
+
gr.Textbox(
|
| 41 |
+
value="You are a friendly Chatbot. Respond only in bisaya language. No english translation.",
|
| 42 |
+
label="System message",
|
| 43 |
+
visible=False,
|
| 44 |
+
),
|
| 45 |
+
gr.Slider(
|
| 46 |
+
minimum=1,
|
| 47 |
+
maximum=2048,
|
| 48 |
+
value=512,
|
| 49 |
+
step=1,
|
| 50 |
+
label="Max new tokens",
|
| 51 |
+
visible=False,
|
| 52 |
+
),
|
| 53 |
+
gr.Slider(
|
| 54 |
+
minimum=0.1,
|
| 55 |
+
maximum=4.0,
|
| 56 |
+
value=0.7,
|
| 57 |
+
step=0.1,
|
| 58 |
+
label="Temperature",
|
| 59 |
+
visible=False,
|
| 60 |
+
),
|
| 61 |
gr.Slider(
|
| 62 |
minimum=0.1,
|
| 63 |
maximum=1.0,
|
| 64 |
value=0.95,
|
| 65 |
step=0.05,
|
| 66 |
label="Top-p (nucleus sampling)",
|
| 67 |
+
visible=False,
|
| 68 |
),
|
| 69 |
],
|
| 70 |
)
|
| 71 |
|
|
|
|
| 72 |
if __name__ == "__main__":
|
| 73 |
demo.launch()
|