Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Load Codestral model and tokenizer
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
codestral_model.to("cuda")
|
| 9 |
|
| 10 |
def respond(
|
|
@@ -28,10 +37,10 @@ def respond(
|
|
| 28 |
input_text = message
|
| 29 |
inputs = codestral_tokenizer(input_text, return_tensors="pt").to("cuda")
|
| 30 |
generated_ids = codestral_model.generate(
|
| 31 |
-
inputs["input_ids"],
|
| 32 |
-
max_new_tokens=max_tokens,
|
| 33 |
-
do_sample=True,
|
| 34 |
-
temperature=temperature,
|
| 35 |
top_p=top_p
|
| 36 |
)
|
| 37 |
result = codestral_tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
|
|
|
| 1 |
+
from huggingface_hub import snapshot_download
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
mistral_models_path = Path.home().joinpath('mistral_models', 'Mamba-Codestral-7B-v0.1')
|
| 5 |
+
mistral_models_path.mkdir(parents=True, exist_ok=True)
|
| 6 |
+
|
| 7 |
+
snapshot_download(repo_id="mistralai/Mamba-Codestral-7B-v0.1", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
|
| 8 |
+
|
| 9 |
import gradio as gr
|
| 10 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 11 |
import torch
|
| 12 |
|
| 13 |
+
# Load Codestral Mamba model and tokenizer
|
| 14 |
+
model_path = str(Path.home().joinpath('mistral_models', 'Mamba-Codestral-7B-v0.1'))
|
| 15 |
+
codestral_model = AutoModelForCausalLM.from_pretrained(model_path)
|
| 16 |
+
codestral_tokenizer = AutoTokenizer.from_pretrained(model_path)
|
| 17 |
codestral_model.to("cuda")
|
| 18 |
|
| 19 |
def respond(
|
|
|
|
| 37 |
input_text = message
|
| 38 |
inputs = codestral_tokenizer(input_text, return_tensors="pt").to("cuda")
|
| 39 |
generated_ids = codestral_model.generate(
|
| 40 |
+
inputs["input_ids"],
|
| 41 |
+
max_new_tokens=max_tokens,
|
| 42 |
+
do_sample=True,
|
| 43 |
+
temperature=temperature,
|
| 44 |
top_p=top_p
|
| 45 |
)
|
| 46 |
result = codestral_tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|