Spaces:
Runtime error
Runtime error
HAITAME LAFRAME
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,14 +2,34 @@ import subprocess
|
|
2 |
import sys
|
3 |
import os
|
4 |
|
|
|
|
|
|
|
|
|
5 |
# Vérifiez si torch est installé, sinon installez-le
|
6 |
try:
|
7 |
import torch
|
8 |
except ImportError:
|
9 |
print("Torch n'est pas installé. Installation de torch...")
|
10 |
-
|
11 |
import torch
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# Installer flash-attn
|
14 |
subprocess.run(
|
15 |
"pip install flash-attn --no-build-isolation",
|
@@ -18,11 +38,6 @@ subprocess.run(
|
|
18 |
)
|
19 |
|
20 |
import gradio as gr
|
21 |
-
from transformers import (
|
22 |
-
AutoModelForCausalLM,
|
23 |
-
AutoTokenizer,
|
24 |
-
TextIteratorStreamer,
|
25 |
-
)
|
26 |
from threading import Thread
|
27 |
|
28 |
# Obtenir le token d'authentification Hugging Face
|
|
|
2 |
import sys
|
3 |
import os
|
4 |
|
5 |
+
# Fonction pour installer un package si non présent
|
6 |
+
def install_package(package_name):
|
7 |
+
subprocess.run([sys.executable, "-m", "pip", "install", package_name], check=True)
|
8 |
+
|
9 |
# Vérifiez si torch est installé, sinon installez-le
|
10 |
try:
|
11 |
import torch
|
12 |
except ImportError:
|
13 |
print("Torch n'est pas installé. Installation de torch...")
|
14 |
+
install_package("torch")
|
15 |
import torch
|
16 |
|
17 |
+
# Vérifiez si transformers est installé, sinon installez-le
|
18 |
+
try:
|
19 |
+
from transformers import (
|
20 |
+
AutoModelForCausalLM,
|
21 |
+
AutoTokenizer,
|
22 |
+
TextIteratorStreamer,
|
23 |
+
)
|
24 |
+
except ImportError:
|
25 |
+
print("Transformers n'est pas installé. Installation de transformers...")
|
26 |
+
install_package("transformers")
|
27 |
+
from transformers import (
|
28 |
+
AutoModelForCausalLM,
|
29 |
+
AutoTokenizer,
|
30 |
+
TextIteratorStreamer,
|
31 |
+
)
|
32 |
+
|
33 |
# Installer flash-attn
|
34 |
subprocess.run(
|
35 |
"pip install flash-attn --no-build-isolation",
|
|
|
38 |
)
|
39 |
|
40 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
41 |
from threading import Thread
|
42 |
|
43 |
# Obtenir le token d'authentification Hugging Face
|