Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
# Initialize the client for ZeroGPU-powered model
|
5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
6 |
|
7 |
-
# Response function
|
8 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
9 |
messages = [{"role": "system", "content": system_message}]
|
10 |
|
@@ -28,44 +26,18 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
28 |
response += token
|
29 |
yield response
|
30 |
|
31 |
-
|
32 |
-
with gr.Blocks(css=".gr-box { border-radius: 12px; padding: 16px; }") as demo:
|
33 |
-
gr.Markdown(
|
34 |
-
"""
|
35 |
-
# 🤖 Zephyr-7B Chatbot (ZeroGPU Powered)
|
36 |
-
Talk to the `HuggingFaceH4/zephyr-7b-beta` model in real-time using ZeroGPU.
|
37 |
-
Customize generation settings below.
|
38 |
-
""",
|
39 |
-
elem_classes=["gr-box"]
|
40 |
-
)
|
41 |
-
|
42 |
chatbot = gr.Chatbot(label="Chat", show_copy_button=True, type="messages")
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
system_msg
|
46 |
-
label="🧠 System Prompt",
|
47 |
-
value="You are a friendly assistant.",
|
48 |
-
lines=2,
|
49 |
-
interactive=True,
|
50 |
-
scale=2
|
51 |
-
)
|
52 |
-
with gr.Row():
|
53 |
-
max_tokens = gr.Slider(1, 2048, value=512, step=1, label="Max Tokens")
|
54 |
-
temperature = gr.Slider(0.1, 4.0, value=0.7, step=0.1, label="Temperature")
|
55 |
-
top_p = gr.Slider(0.1, 1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
56 |
-
|
57 |
-
msg_input = gr.Textbox(label="💬 Your message", placeholder="Type a message and press Enter...")
|
58 |
-
|
59 |
-
# Bind function to chat
|
60 |
-
def user_submit(user_message, history, system_message, max_tokens, temperature, top_p):
|
61 |
-
return respond(user_message, history, system_message, max_tokens, temperature, top_p)
|
62 |
|
63 |
-
msg_input.submit(
|
64 |
-
fn=user_submit,
|
65 |
-
inputs=[msg_input, chatbot, system_msg, max_tokens, temperature, top_p],
|
66 |
-
outputs=chatbot
|
67 |
-
)
|
68 |
|
69 |
-
# Launch
|
70 |
if __name__ == "__main__":
|
71 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
|
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
|
|
6 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
7 |
messages = [{"role": "system", "content": system_message}]
|
8 |
|
|
|
26 |
response += token
|
27 |
yield response
|
28 |
|
29 |
+
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
chatbot = gr.Chatbot(label="Chat", show_copy_button=True, type="messages")
|
31 |
+
system_msg = gr.Textbox(value="You are a helpful assistant.", label="System Message")
|
32 |
+
max_tokens = gr.Slider(1, 2048, value=512, label="Max Tokens")
|
33 |
+
temperature = gr.Slider(0.1, 4.0, value=0.7, label="Temperature")
|
34 |
+
top_p = gr.Slider(0.1, 1.0, value=0.95, label="Top-p")
|
35 |
+
msg_input = gr.Textbox(label="Message", placeholder="Ask me anything...")
|
36 |
|
37 |
+
def chat_fn(msg, history, system_msg, max_tokens, temperature, top_p):
|
38 |
+
return respond(msg, history, system_msg, max_tokens, temperature, top_p)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
+
msg_input.submit(chat_fn, [msg_input, chatbot, system_msg, max_tokens, temperature, top_p], chatbot)
|
|
|
|
|
|
|
|
|
41 |
|
|
|
42 |
if __name__ == "__main__":
|
43 |
demo.launch()
|