Spaces:
Runtime error
Runtime error
Initial SCLM Chat Demo
Browse files- README.md +17 -6
- app.py +75 -0
- requirements.txt +8 -0
README.md
CHANGED
|
@@ -1,12 +1,23 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: SCLM Chat Demo
|
| 3 |
+
emoji: 🧠
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# 🧠 SCLM - Stateful Coherent Language Model
|
| 14 |
+
|
| 15 |
+
Demo interactive du modèle SCLM avec architecture EARCP.
|
| 16 |
+
|
| 17 |
+
## Features
|
| 18 |
+
- État latent persistant
|
| 19 |
+
- Cohérence contextuelle améliorée
|
| 20 |
+
- Architecture MoE (Mixture of Experts)
|
| 21 |
+
|
| 22 |
+
## Author
|
| 23 |
+
Mike Amega (Ame Web Studio)
|
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
import json
|
| 7 |
+
|
| 8 |
+
# ============================================================
|
| 9 |
+
# SCLM Classes (simplifié pour le Space)
|
| 10 |
+
# ============================================================
|
| 11 |
+
|
| 12 |
+
# [Inclure ici les classes SCLMConfigB, EARCPModuleB, SCLMModelOptionB]
|
| 13 |
+
# Pour simplifier, ce Space utilise le modèle de base avec une interface
|
| 14 |
+
|
| 15 |
+
print("🔄 Chargement du modèle...")
|
| 16 |
+
|
| 17 |
+
# Charger Llama
|
| 18 |
+
quant_config = BitsAndBytesConfig(
|
| 19 |
+
load_in_4bit=True,
|
| 20 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 24 |
+
"meta-llama/Llama-3.2-1B",
|
| 25 |
+
quantization_config=quant_config,
|
| 26 |
+
device_map="auto",
|
| 27 |
+
token=True
|
| 28 |
+
)
|
| 29 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-1B", token=True)
|
| 30 |
+
|
| 31 |
+
def chat(message, history, temperature, max_tokens):
|
| 32 |
+
# Build prompt
|
| 33 |
+
prompt = "You are a helpful AI assistant.
|
| 34 |
+
|
| 35 |
+
"
|
| 36 |
+
for h in history:
|
| 37 |
+
prompt += f"User: {h[0]}
|
| 38 |
+
Assistant: {h[1]}
|
| 39 |
+
"
|
| 40 |
+
prompt += f"User: {message}
|
| 41 |
+
Assistant:"
|
| 42 |
+
|
| 43 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 44 |
+
|
| 45 |
+
with torch.no_grad():
|
| 46 |
+
outputs = model.generate(
|
| 47 |
+
inputs.input_ids,
|
| 48 |
+
max_new_tokens=int(max_tokens),
|
| 49 |
+
temperature=temperature,
|
| 50 |
+
do_sample=True,
|
| 51 |
+
top_p=0.9,
|
| 52 |
+
pad_token_id=tokenizer.eos_token_id
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 56 |
+
response = response[len(prompt):].split("User:")[0].strip()
|
| 57 |
+
|
| 58 |
+
return response
|
| 59 |
+
|
| 60 |
+
demo = gr.ChatInterface(
|
| 61 |
+
chat,
|
| 62 |
+
title="🧠 SCLM Chat Demo",
|
| 63 |
+
description="Stateful Coherent Language Model - Demo",
|
| 64 |
+
additional_inputs=[
|
| 65 |
+
gr.Slider(0.1, 1.5, 0.7, label="Temperature"),
|
| 66 |
+
gr.Slider(50, 300, 150, label="Max Tokens"),
|
| 67 |
+
],
|
| 68 |
+
examples=[
|
| 69 |
+
["Bonjour! Comment vas-tu?"],
|
| 70 |
+
["Explique-moi ce qu'est l'intelligence artificielle"],
|
| 71 |
+
["Raconte-moi une histoire courte"],
|
| 72 |
+
]
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio>=4.0.0
|
| 2 |
+
transformers>=4.35.0
|
| 3 |
+
accelerate
|
| 4 |
+
bitsandbytes
|
| 5 |
+
torch
|
| 6 |
+
huggingface_hub
|
| 7 |
+
sentencepiece
|
| 8 |
+
protobuf==3.20.3
|