FPll commited on
Commit
f9a7324
·
verified ·
1 Parent(s): 8e2b0d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -3,34 +3,38 @@ from huggingface_hub import hf_hub_download
3
  from llama_cpp import Llama
4
  import os
5
 
6
- # 1. Scarichiamo il modello dal tuo repository
7
- # Se hai salvato il token nei "Secrets" della Space, lo legge in automatico
8
- token = os.getenv("HF_TOKEN")
 
9
 
10
- print("⏬ Scaricamento del modello Limba...")
 
 
11
  model_path = hf_hub_download(
12
  repo_id="FPll/Limba-1.0",
13
  filename="Meta-Llama-3.1-8B.Q4_K_M.gguf",
14
  token=token
15
  )
16
 
17
- # 2. Inizializziamo il modello
 
 
18
  llm = Llama(model_path=model_path, n_ctx=2048, n_threads=4)
19
 
20
  def respond(message, history):
21
- # Formattiamo il prompt per Llama 3.1
22
  prompt = f"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n{message}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
23
 
24
  response = llm(prompt, max_tokens=512, stop=["<|eot_id|>"], echo=False)
25
  return response["choices"][0]["text"].strip()
26
 
27
- # 3. Interfaccia Gradio (Il vestito del Chatbot)
28
  demo = gr.ChatInterface(
29
  respond,
30
  title="Limba 1.0 - Progetto Margherita",
31
  description="Su primu protòtipu de IA pro s'iscola sarda. Parla-mi in sardu o de fìsica e matemàtica!",
32
- examples=["Iscrie sa fòrmula de s'energia tzinetica", "Chie est istadu Enricu Fermi?", "A ite zerbit sa derivata?"],
33
- theme="soft"
34
  )
35
 
36
  if __name__ == "__main__":
 
3
  from llama_cpp import Llama
4
  import os
5
 
6
+ # 1. Recupero e pulizia del Token
7
+ token = os.getenv("HF_TOKEN")
8
+ if token:
9
+ token = token.strip()
10
 
11
+ print(f"⏬ Scaricamento del modello Limba...")
12
+
13
+ # Scarichiamo il modello
14
  model_path = hf_hub_download(
15
  repo_id="FPll/Limba-1.0",
16
  filename="Meta-Llama-3.1-8B.Q4_K_M.gguf",
17
  token=token
18
  )
19
 
20
+ print("✅ Modello caricato! Accendo i motori...")
21
+
22
+ # 2. Inizializzazione del modello (Ottimizzato per 4 thread)
23
  llm = Llama(model_path=model_path, n_ctx=2048, n_threads=4)
24
 
25
  def respond(message, history):
26
+ # Formato prompt per Llama 3.1
27
  prompt = f"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n{message}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n"
28
 
29
  response = llm(prompt, max_tokens=512, stop=["<|eot_id|>"], echo=False)
30
  return response["choices"][0]["text"].strip()
31
 
32
+ # 3. Interfaccia Chat (Ho rimosso 'theme' che dava errore)
33
  demo = gr.ChatInterface(
34
  respond,
35
  title="Limba 1.0 - Progetto Margherita",
36
  description="Su primu protòtipu de IA pro s'iscola sarda. Parla-mi in sardu o de fìsica e matemàtica!",
37
+ examples=["Iscrie sa fòrmula de s'energia tzinetica", "Chie est istadu Enricu Fermi?", "A ite zerbit sa derivata?"]
 
38
  )
39
 
40
  if __name__ == "__main__":