Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,52 @@ import gradio as gr
|
|
2 |
import subprocess
|
3 |
import threading
|
4 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# Fonction pour lancer train.py en arrière-plan
|
7 |
def train_model():
|
8 |
-
process = subprocess.Popen(["python", "
|
9 |
stdout, stderr = process.communicate()
|
10 |
-
return stdout.decode() + "\n" + stderr.decode() # Retourne les logs
|
11 |
|
12 |
-
#
|
13 |
threading.Thread(target=train_model, daemon=True).start()
|
14 |
|
15 |
-
# ✅
|
16 |
time.sleep(3)
|
17 |
|
18 |
# Interface Gradio
|
|
|
2 |
import subprocess
|
3 |
import threading
|
4 |
import time
|
5 |
+
from huggingface_hub import InferenceClient
|
6 |
+
|
7 |
+
# Définir la fonction `respond` avant de l'utiliser
|
8 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
+
|
10 |
+
def respond(
|
11 |
+
message,
|
12 |
+
history: list[tuple[str, str]],
|
13 |
+
system_message,
|
14 |
+
max_tokens,
|
15 |
+
temperature,
|
16 |
+
top_p,
|
17 |
+
):
|
18 |
+
messages = [{"role": "system", "content": system_message}]
|
19 |
+
|
20 |
+
for val in history:
|
21 |
+
if val[0]:
|
22 |
+
messages.append({"role": "user", "content": val[0]})
|
23 |
+
if val[1]:
|
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 |
+
response += token
|
39 |
+
yield response
|
40 |
|
41 |
# Fonction pour lancer train.py en arrière-plan
|
42 |
def train_model():
|
43 |
+
process = subprocess.Popen(["python", "train.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
44 |
stdout, stderr = process.communicate()
|
45 |
+
return stdout.decode() + "\n" + stderr.decode() # Retourne les logs d'entraînement
|
46 |
|
47 |
+
# Lancer l'entraînement en arrière-plan
|
48 |
threading.Thread(target=train_model, daemon=True).start()
|
49 |
|
50 |
+
# ✅ Ajout d'un délai pour éviter les conflits au démarrage
|
51 |
time.sleep(3)
|
52 |
|
53 |
# Interface Gradio
|