Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def respond(
|
| 6 |
message,
|
|
@@ -9,17 +18,13 @@ def respond(
|
|
| 9 |
max_tokens,
|
| 10 |
temperature,
|
| 11 |
top_p,
|
|
|
|
| 12 |
hf_token: gr.OAuthToken,
|
| 13 |
):
|
| 14 |
-
|
| 15 |
-
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
|
| 16 |
-
"""
|
| 17 |
-
client = InferenceClient(token=hf_token.token, model="openai/gpt-oss-20b")
|
| 18 |
|
| 19 |
messages = [{"role": "system", "content": system_message}]
|
| 20 |
-
|
| 21 |
messages.extend(history)
|
| 22 |
-
|
| 23 |
messages.append({"role": "user", "content": message})
|
| 24 |
|
| 25 |
response = ""
|
|
@@ -40,9 +45,6 @@ def respond(
|
|
| 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 |
chatbot = gr.ChatInterface(
|
| 47 |
respond,
|
| 48 |
additional_inputs=[
|
|
@@ -56,14 +58,22 @@ chatbot = gr.ChatInterface(
|
|
| 56 |
step=0.05,
|
| 57 |
label="Top-p (nucleus sampling)",
|
| 58 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
],
|
| 60 |
)
|
| 61 |
|
| 62 |
with gr.Blocks() as demo:
|
| 63 |
with gr.Sidebar():
|
| 64 |
gr.LoginButton()
|
|
|
|
|
|
|
| 65 |
chatbot.render()
|
| 66 |
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
AVAILABLE_MODELS = [
|
| 5 |
+
"openai/gpt-oss-20b",
|
| 6 |
+
"openai/gpt-oss-mini-20b",
|
| 7 |
+
"meta-llama/Llama-3.3-70B-Instruct",
|
| 8 |
+
"meta-llama/Llama-3.1-8B-Instruct",
|
| 9 |
+
"mistralai/Mistral-7B-Instruct-v0.3",
|
| 10 |
+
"Qwen/Qwen2.5-72B-Instruct",
|
| 11 |
+
"microsoft/Phi-3.5-mini-instruct",
|
| 12 |
+
]
|
| 13 |
|
| 14 |
def respond(
|
| 15 |
message,
|
|
|
|
| 18 |
max_tokens,
|
| 19 |
temperature,
|
| 20 |
top_p,
|
| 21 |
+
model_name,
|
| 22 |
hf_token: gr.OAuthToken,
|
| 23 |
):
|
| 24 |
+
client = InferenceClient(token=hf_token.token, model=model_name)
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
| 27 |
messages.extend(history)
|
|
|
|
| 28 |
messages.append({"role": "user", "content": message})
|
| 29 |
|
| 30 |
response = ""
|
|
|
|
| 45 |
yield response
|
| 46 |
|
| 47 |
|
|
|
|
|
|
|
|
|
|
| 48 |
chatbot = gr.ChatInterface(
|
| 49 |
respond,
|
| 50 |
additional_inputs=[
|
|
|
|
| 58 |
step=0.05,
|
| 59 |
label="Top-p (nucleus sampling)",
|
| 60 |
),
|
| 61 |
+
gr.Dropdown(
|
| 62 |
+
choices=AVAILABLE_MODELS,
|
| 63 |
+
value=AVAILABLE_MODELS[0],
|
| 64 |
+
label="🤖 Model",
|
| 65 |
+
info="Chọn model để chat",
|
| 66 |
+
),
|
| 67 |
],
|
| 68 |
)
|
| 69 |
|
| 70 |
with gr.Blocks() as demo:
|
| 71 |
with gr.Sidebar():
|
| 72 |
gr.LoginButton()
|
| 73 |
+
gr.Markdown("### ⚙️ Cài đặt")
|
| 74 |
+
gr.Markdown("Đăng nhập để sử dụng các model HuggingFace.")
|
| 75 |
chatbot.render()
|
| 76 |
|
| 77 |
|
| 78 |
if __name__ == "__main__":
|
| 79 |
+
demo.launch()
|