Spaces:
Sleeping
Sleeping
Keira James
commited on
Commit
·
cb9643e
1
Parent(s):
c98706e
update to gradio 2
Browse files
app.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
#
|
| 5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
|
| 7 |
-
# Define the chat response function
|
| 8 |
def respond(
|
| 9 |
message,
|
| 10 |
history: list[tuple[str, str]],
|
|
@@ -33,19 +32,82 @@ def respond(
|
|
| 33 |
top_p=top_p,
|
| 34 |
):
|
| 35 |
token = message.choices[0].delta.content
|
|
|
|
| 36 |
response += token
|
| 37 |
yield response
|
| 38 |
|
| 39 |
-
#
|
| 40 |
demo = gr.ChatInterface(
|
| 41 |
respond,
|
| 42 |
additional_inputs=[
|
| 43 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
|
|
|
|
|
|
|
|
|
| 44 |
],
|
| 45 |
-
css="
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# Set up the InferenceClient for the chatbot
|
| 5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
|
|
|
|
| 7 |
def respond(
|
| 8 |
message,
|
| 9 |
history: list[tuple[str, str]],
|
|
|
|
| 32 |
top_p=top_p,
|
| 33 |
):
|
| 34 |
token = message.choices[0].delta.content
|
| 35 |
+
|
| 36 |
response += token
|
| 37 |
yield response
|
| 38 |
|
| 39 |
+
# Define the interface with styling and customization
|
| 40 |
demo = gr.ChatInterface(
|
| 41 |
respond,
|
| 42 |
additional_inputs=[
|
| 43 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message", lines=1),
|
| 44 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 45 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 46 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
| 47 |
],
|
| 48 |
+
css="""
|
| 49 |
+
/* Custom CSS to style the interface */
|
| 50 |
+
.gradio-container {
|
| 51 |
+
background-color: #222222; /* Dark background */
|
| 52 |
+
color: #f4f4f4; /* Light text */
|
| 53 |
+
font-family: 'Arial', sans-serif;
|
| 54 |
+
border-radius: 12px;
|
| 55 |
+
padding: 20px;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
.gradio-button {
|
| 59 |
+
background-color: #ff4081; /* Pink buttons */
|
| 60 |
+
color: white;
|
| 61 |
+
border-radius: 10px;
|
| 62 |
+
font-size: 16px;
|
| 63 |
+
padding: 12px 24px;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
.gradio-button:hover {
|
| 67 |
+
background-color: #e91e63; /* Darker pink on hover */
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
.gradio-textbox {
|
| 71 |
+
background-color: #333333; /* Dark background for textboxes */
|
| 72 |
+
border-radius: 12px;
|
| 73 |
+
color: #f4f4f4; /* Light text inside the textboxes */
|
| 74 |
+
padding: 12px;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.gradio-chat {
|
| 78 |
+
background-color: #333333;
|
| 79 |
+
border-radius: 12px;
|
| 80 |
+
padding: 16px;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
.gradio-chat .gradio-message-user {
|
| 84 |
+
background-color: #ff4081; /* Pink background for user messages */
|
| 85 |
+
border-radius: 12px;
|
| 86 |
+
color: #f4f4f4;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
.gradio-chat .gradio-message-assistant {
|
| 90 |
+
background-color: #555555; /* Darker background for assistant messages */
|
| 91 |
+
border-radius: 12px;
|
| 92 |
+
color: #f4f4f4;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
.gradio-container h1 {
|
| 96 |
+
color: #ff4081; /* Title in pink */
|
| 97 |
+
font-size: 36px;
|
| 98 |
+
text-align: center;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
.gradio-container .gradio-textbox input {
|
| 102 |
+
font-size: 16px;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
.gradio-container p {
|
| 106 |
+
color: #bdbdbd; /* Light grey description text */
|
| 107 |
+
text-align: center;
|
| 108 |
+
font-size: 14px;
|
| 109 |
+
}
|
| 110 |
+
"""
|
| 111 |
)
|
| 112 |
|
| 113 |
if __name__ == "__main__":
|