FPll commited on
Commit
0cbd70a
·
verified ·
1 Parent(s): 90994d6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ 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__":
37
+ demo.launch(server_name="0.0.0.0", server_port=7860)