Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
---
|
| 4 |
+
# 🧠 QA LLM – Utilisation du Modèle
|
| 5 |
+
|
| 6 |
+
Ce projet fournit un modèle de langage fine-tuné pour répondre à des questions en français.
|
| 7 |
+
Voici comment l'utiliser dans ton propre code, ou via l’interface Gradio.
|
| 8 |
+
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
## 📦 Installation
|
| 12 |
+
|
| 13 |
+
Installe les dépendances nécessaires :
|
| 14 |
+
|
| 15 |
+
```bash
|
| 16 |
+
pip install torch transformers gradio
|
| 17 |
+
🚀 Charger le modèle et générer une réponse
|
| 18 |
+
python
|
| 19 |
+
Copy code
|
| 20 |
+
import torch
|
| 21 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 22 |
+
|
| 23 |
+
model_dir = "qa_llm_model"
|
| 24 |
+
|
| 25 |
+
tokenizer = AutoTokenizer.from_pretrained(model_dir)
|
| 26 |
+
model = AutoModelForCausalLM.from_pretrained(model_dir)
|
| 27 |
+
|
| 28 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 29 |
+
model.to(device)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def generate_answer(question, max_new_tokens=128, temperature=0.8, top_p=0.9):
|
| 33 |
+
prompt = f"Question: {question}\nRéponse:"
|
| 34 |
+
|
| 35 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
| 36 |
+
|
| 37 |
+
with torch.no_grad():
|
| 38 |
+
outputs = model.generate(
|
| 39 |
+
**inputs,
|
| 40 |
+
max_new_tokens=max_new_tokens,
|
| 41 |
+
do_sample=True,
|
| 42 |
+
top_p=top_p,
|
| 43 |
+
temperature=temperature,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
full_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 47 |
+
|
| 48 |
+
if "Réponse:" in full_text:
|
| 49 |
+
answer_part = full_text.split("Réponse:", 1)[1]
|
| 50 |
+
else:
|
| 51 |
+
answer_part = full_text
|
| 52 |
+
|
| 53 |
+
if "<EOS>" in answer_part:
|
| 54 |
+
answer_part = answer_part.split("<EOS>")[0]
|
| 55 |
+
|
| 56 |
+
return answer_part.strip()
|
| 57 |
+
🎛 Interface Gradio
|
| 58 |
+
python
|
| 59 |
+
Copy code
|
| 60 |
+
import gradio as gr
|
| 61 |
+
|
| 62 |
+
iface = gr.Interface(
|
| 63 |
+
fn=generate_answer,
|
| 64 |
+
inputs=[
|
| 65 |
+
gr.Textbox(lines=2, label="Ta question"),
|
| 66 |
+
gr.Slider(16, 512, value=128, step=16, label="max_new_tokens"),
|
| 67 |
+
gr.Slider(0.1, 1.5, value=0.8, step=0.05, label="temperature"),
|
| 68 |
+
gr.Slider(0.1, 1.0, value=0.9, step=0.05, label="top_p"),
|
| 69 |
+
],
|
| 70 |
+
outputs=gr.Textbox(lines=8, label="Réponse de l'IA"),
|
| 71 |
+
title="QA LLM",
|
| 72 |
+
description="Pose une question en français et le modèle génère une réponse.",
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
iface.launch(share=True)
|
| 76 |
+
▶️ Lancer l’interface
|
| 77 |
+
bash
|
| 78 |
+
Copy code
|
| 79 |
+
python app.py
|
| 80 |
+
|
| 81 |
+
📜 Licence
|
| 82 |
+
À adapter selon ton projet.
|