Spaces:
Runtime error
Runtime error
martianband1t
commited on
Commit
•
e2739e0
1
Parent(s):
a8f9af0
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,98 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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("models/meta-llama/Meta-Llama-3-70B-Instruct")
|
8 |
+
|
9 |
+
css = """
|
10 |
+
body, html {
|
11 |
+
height: 100%;
|
12 |
+
margin: 0;
|
13 |
+
font-family: Arial, Helvetica, sans-serif;
|
14 |
+
position: relative;
|
15 |
+
}
|
16 |
+
body::before {
|
17 |
+
content: "";
|
18 |
+
background-image: url('./favicon.jpg');
|
19 |
+
background-size: cover;
|
20 |
+
background-repeat: no-repeat;
|
21 |
+
background-attachment: fixed;
|
22 |
+
opacity: 0.5; /* Ajustez l'opacité ici pour la transparence */
|
23 |
+
top: 0;
|
24 |
+
left: 0;
|
25 |
+
bottom: 0;
|
26 |
+
right: 0;
|
27 |
+
position: absolute;
|
28 |
+
z-index: -1; /* Placez l'image derrière le contenu */
|
29 |
+
}
|
30 |
+
h1 {
|
31 |
+
background: radial-gradient(circle, red, black);
|
32 |
+
-webkit-background-clip: text;
|
33 |
+
-webkit-text-fill-color: transparent;
|
34 |
+
font-size: 2em;
|
35 |
+
text-align: center;
|
36 |
+
margin-top: 0;
|
37 |
+
}
|
38 |
+
"""
|
39 |
+
|
40 |
+
def respond(
|
41 |
+
message,
|
42 |
+
history: list[tuple[str, str]],
|
43 |
+
system_message,
|
44 |
+
max_tokens,
|
45 |
+
temperature,
|
46 |
+
top_p,
|
47 |
+
):
|
48 |
+
messages = [{"role": "system", "content": system_message}]
|
49 |
+
|
50 |
+
for val in history:
|
51 |
+
if val[0]:
|
52 |
+
messages.append({"role": "user", "content": val[0]})
|
53 |
+
if val[1]:
|
54 |
+
messages.append({"role": "assistant", "content": val[1]})
|
55 |
+
|
56 |
+
messages.append({"role": "user", "content": message})
|
57 |
+
|
58 |
+
response = ""
|
59 |
+
|
60 |
+
for message in client.chat_completion(
|
61 |
+
messages,
|
62 |
+
max_tokens=max_tokens,
|
63 |
+
stream=True,
|
64 |
+
temperature=temperature,
|
65 |
+
top_p=top_p,
|
66 |
+
):
|
67 |
+
token = message.choices[0].delta.content
|
68 |
+
|
69 |
+
response += token
|
70 |
+
yield response
|
71 |
+
|
72 |
+
"""
|
73 |
+
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
74 |
+
"""
|
75 |
+
demo = gr.ChatInterface(
|
76 |
+
fn=respond,
|
77 |
+
css=css,
|
78 |
+
title="Voici notre Chatbot: Le Spéc'IA'liste du vrac",
|
79 |
+
examples=[
|
80 |
+
["Calcul moi ma facture si j'ai 12 pied par 35 pied de gravier 0-3/4 pour un epaisseur de 3 pouces en livraison zone 4"],
|
81 |
+
["Je veux connaitre les produits de paillis chez le specialiste du vrai"]
|
82 |
+
],
|
83 |
+
additional_inputs=[
|
84 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
85 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
86 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
87 |
+
gr.Slider(
|
88 |
+
minimum=0.1,
|
89 |
+
maximum=1.0,
|
90 |
+
value=0.95,
|
91 |
+
step=0.05,
|
92 |
+
label="Top-p (echantillons nucleus)",
|
93 |
+
)
|
94 |
+
]
|
95 |
+
)
|
96 |
+
|
97 |
+
if __name__ == "__main__":
|
98 |
+
demo.launch()
|