Spaces:
Runtime error
Runtime error
File size: 1,004 Bytes
abae4ba cef7739 42a9e51 cef7739 55e69e1 7fa7ea5 55e69e1 abae4ba 55e69e1 42a9e51 8c7c0d7 cef7739 55e69e1 abae4ba 55e69e1 abae4ba 55e69e1 abae4ba 55e69e1 8c7c0d7 abae4ba ab1672e abae4ba 55e69e1 abae4ba cef7739 42a9e51 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 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() |