Ronaldodev commited on
Commit
dcdbd59
·
verified ·
1 Parent(s): 5e6267d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -5,11 +5,20 @@ from fastapi import FastAPI
5
  from pydantic import BaseModel
6
  import uvicorn
7
  import threading
 
 
 
 
8
 
9
  # --- 1. Charger le modèle ---
10
- model_name_or_path = "facebook/MobileLLM-Pro" # ou ton chemin local si téléchargé
11
- tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
12
- model = AutoModelForCausalLM.from_pretrained(model_name_or_path, torch_dtype=torch.float16, device_map="auto")
 
 
 
 
 
13
  model.eval()
14
 
15
  # --- 2. Fonction de prédiction ---
@@ -28,7 +37,7 @@ def launch_gradio():
28
  title="MobileLLM-Pro Chat",
29
  description="Interface Gradio pour MobileLLM-Pro"
30
  )
31
- iface.launch(server_name="0.0.0.0", server_port=7860)
32
 
33
  # --- 4. API FastAPI ---
34
  app = FastAPI()
 
5
  from pydantic import BaseModel
6
  import uvicorn
7
  import threading
8
+ from huggingface_hub import notebook_login
9
+
10
+ # --- 0. Authentification Hugging Face dans le Space ---
11
+ notebook_login() # ouvre une fenêtre pour te connecter si nécessaire
12
 
13
  # --- 1. Charger le modèle ---
14
+ model_name_or_path = "facebook/MobileLLM-Pro" # modèle gated
15
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_auth_token=True)
16
+ model = AutoModelForCausalLM.from_pretrained(
17
+ model_name_or_path,
18
+ use_auth_token=True,
19
+ torch_dtype=torch.float16,
20
+ device_map="auto"
21
+ )
22
  model.eval()
23
 
24
  # --- 2. Fonction de prédiction ---
 
37
  title="MobileLLM-Pro Chat",
38
  description="Interface Gradio pour MobileLLM-Pro"
39
  )
40
+ iface.launch(server_name="0.0.0.0", server_port=7860, share=True) # share=True pour accéder depuis le web
41
 
42
  # --- 4. API FastAPI ---
43
  app = FastAPI()