Spaces:
Runtime error
Runtime error
Moine Frédéric commited on
Commit ·
6641d23
1
Parent(s): 0e1d418
Update chatbot with Gradio
Browse files- .gradio/flagged/dataset1.csv +2 -0
- ChatBotOneWater +1 -0
- app.py +28 -60
- get-pip.py +0 -0
- requirements.txt +5 -1
.gradio/flagged/dataset1.csv
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Texte à encoder,Vecteur d'embedding,timestamp
|
| 2 |
+
,,2025-03-06 16:48:31.797841
|
ChatBotOneWater
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Subproject commit 0e1d41824f82a28277eef19eeb45bcc2fe9311e1
|
app.py
CHANGED
|
@@ -1,64 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
)
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
-
|
| 26 |
-
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
-
response = ""
|
| 29 |
-
|
| 30 |
-
for message in client.chat_completion(
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=max_tokens,
|
| 33 |
-
stream=True,
|
| 34 |
-
temperature=temperature,
|
| 35 |
-
top_p=top_p,
|
| 36 |
-
):
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
-
response += token
|
| 40 |
-
yield response
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
""
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
additional_inputs=[
|
| 49 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 50 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 52 |
-
gr.Slider(
|
| 53 |
-
minimum=0.1,
|
| 54 |
-
maximum=1.0,
|
| 55 |
-
value=0.95,
|
| 56 |
-
step=0.05,
|
| 57 |
-
label="Top-p (nucleus sampling)",
|
| 58 |
-
),
|
| 59 |
-
],
|
| 60 |
)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
if __name__ == "__main__":
|
| 64 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModel, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Charger le modèle Salesforce Embedding Mistral
|
| 7 |
+
model_name = "Salesforce/SFR-Embedding-Mistral"
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
+
model = AutoModel.from_pretrained(model_name)
|
| 10 |
+
|
| 11 |
+
def embed_text(text):
|
| 12 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True)
|
| 13 |
+
with torch.no_grad():
|
| 14 |
+
embeddings = model(**inputs).last_hidden_state.mean(dim=1).numpy()
|
| 15 |
+
return embeddings
|
| 16 |
+
|
| 17 |
+
# Exemple de fonction de réponse simple (à adapter à tes besoins)
|
| 18 |
+
def chatbot_response(question):
|
| 19 |
+
embedding = embed_text(question)
|
| 20 |
+
return f"Vecteur d'embedding généré (premiers éléments): {embeddings.numpy().flatten()[:5]}"
|
| 21 |
+
|
| 22 |
+
# Interface utilisateur Gradio
|
| 23 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=embed_text,
|
| 27 |
+
inputs=gr.Textbox(label="Texte à encoder"),
|
| 28 |
+
outputs=gr.Textbox(label="Vecteur d'embedding"),
|
| 29 |
+
title="Chatbot Hydrologique avec Salesforce/SFR-Embedding-Mistral"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
+
iface.launch()
|
|
|
|
|
|
get-pip.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
CHANGED
|
@@ -1 +1,5 @@
|
|
| 1 |
-
huggingface_hub==0.25.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub==0.25.2gradio transformers requests
|
| 2 |
+
echo gradio > requirements.txt
|
| 3 |
+
echo transformers >> requirements.txt
|
| 4 |
+
echo requests >> requirements.txt
|
| 5 |
+
|