from llama_cpp import Llama import gradio as gr import os # 📦 Téléchargement simple (stable) MODEL_URL = "https://huggingface.co/Pi3141/TinyLlama-1.1B-Chat-v1.0-GGUF/resolve/main/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf" MODEL_PATH = "tinyllama.gguf" if not os.path.exists(MODEL_PATH): os.system(f"wget -O {MODEL_PATH} {MODEL_URL}") # 🧠 Charger le modèle (optimisé free tier) llm = Llama( model_path=MODEL_PATH, n_ctx=256, n_threads=os.cpu_count(), n_batch=128, verbose=False ) # 💬 Chat rapide + français forcé def chat(user_input): prompt = f"Réponds en français.\nQuestion: {user_input}\nRéponse:" output = llm( prompt, max_tokens=40, temperature=0.3, stop=["Question:"] ) return output["choices"][0]["text"].strip() # 🌐 Interface web demo = gr.Interface( fn=chat, inputs=gr.Textbox(lines=2, placeholder="Pose ta question..."), outputs="text", title="Mon IA (TinyLlama FR)" ) demo.launch()