Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,80 @@
|
|
| 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,
|
|
@@ -40,25 +109,23 @@ def respond(
|
|
| 40 |
yield response
|
| 41 |
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 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("HuggingFaceH4/zephyr-7b-beta")
|
| 5 |
|
| 6 |
+
# Background effect from CodePen
|
| 7 |
+
background_html = """
|
| 8 |
+
<style>
|
| 9 |
+
body {
|
| 10 |
+
margin: 0;
|
| 11 |
+
padding: 0;
|
| 12 |
+
overflow: hidden;
|
| 13 |
+
background: #141414;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
.canvas-container {
|
| 17 |
+
position: absolute;
|
| 18 |
+
top: 0;
|
| 19 |
+
left: 0;
|
| 20 |
+
right: 0;
|
| 21 |
+
bottom: 0;
|
| 22 |
+
z-index: -1;
|
| 23 |
+
display: flex;
|
| 24 |
+
justify-content: center;
|
| 25 |
+
align-items: center;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
canvas {
|
| 29 |
+
display: block;
|
| 30 |
+
width: 100%;
|
| 31 |
+
height: 100%;
|
| 32 |
+
}
|
| 33 |
+
</style>
|
| 34 |
+
|
| 35 |
+
<div class="canvas-container">
|
| 36 |
+
<canvas id="background-effect"></canvas>
|
| 37 |
+
</div>
|
| 38 |
+
|
| 39 |
+
<script>
|
| 40 |
+
const canvas = document.getElementById('background-effect');
|
| 41 |
+
const ctx = canvas.getContext('2d');
|
| 42 |
+
|
| 43 |
+
function resizeCanvas() {
|
| 44 |
+
canvas.width = window.innerWidth;
|
| 45 |
+
canvas.height = window.innerHeight;
|
| 46 |
+
}
|
| 47 |
+
window.addEventListener('resize', resizeCanvas);
|
| 48 |
+
resizeCanvas();
|
| 49 |
+
|
| 50 |
+
function randomInt(min, max) {
|
| 51 |
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
function drawBackground() {
|
| 55 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 56 |
+
|
| 57 |
+
for (let i = 0; i < 100; i++) {
|
| 58 |
+
const x = randomInt(0, canvas.width);
|
| 59 |
+
const y = randomInt(0, canvas.height);
|
| 60 |
+
const radius = randomInt(1, 5);
|
| 61 |
+
const r = randomInt(0, 255);
|
| 62 |
+
const g = randomInt(0, 255);
|
| 63 |
+
const b = randomInt(0, 255);
|
| 64 |
+
const alpha = Math.random();
|
| 65 |
+
|
| 66 |
+
ctx.beginPath();
|
| 67 |
+
ctx.arc(x, y, radius, 0, Math.PI * 2, false);
|
| 68 |
+
ctx.fillStyle = `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
| 69 |
+
ctx.fill();
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
requestAnimationFrame(drawBackground);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
drawBackground();
|
| 76 |
+
</script>
|
| 77 |
+
"""
|
| 78 |
|
| 79 |
def respond(
|
| 80 |
message,
|
|
|
|
| 109 |
yield response
|
| 110 |
|
| 111 |
|
| 112 |
+
with gr.Blocks() as demo:
|
| 113 |
+
gr.HTML(background_html) # Insert the background effect
|
| 114 |
+
gr.ChatInterface(
|
| 115 |
+
respond,
|
| 116 |
+
additional_inputs=[
|
| 117 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 118 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 119 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 120 |
+
gr.Slider(
|
| 121 |
+
minimum=0.1,
|
| 122 |
+
maximum=1.0,
|
| 123 |
+
value=0.95,
|
| 124 |
+
step=0.05,
|
| 125 |
+
label="Top-p (nucleus sampling)",
|
| 126 |
+
),
|
| 127 |
+
],
|
| 128 |
+
)
|
|
|
|
|
|
|
| 129 |
|
| 130 |
if __name__ == "__main__":
|
| 131 |
demo.launch()
|