Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,20 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import LlamaForCausalLM, LlamaTokenizer
|
| 4 |
-
from huggingface_hub import hf_hub_download
|
| 5 |
import torch
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
print("Загрузка токенизатора...")
|
| 10 |
tokenizer = LlamaTokenizer.from_pretrained(model_id)
|
| 11 |
|
| 12 |
-
print("
|
| 13 |
-
|
| 14 |
-
local_dir = os.path.dirname(config_path)
|
| 15 |
-
|
| 16 |
-
# Проверяем файлы весов и делаем линк
|
| 17 |
-
possible_files = ["orion_model.safetensors", "model.safetensors"]
|
| 18 |
-
for f in possible_files:
|
| 19 |
-
try:
|
| 20 |
-
weight_path = hf_hub_download(repo_id=model_id, filename=f)
|
| 21 |
-
standard_path = os.path.join(local_dir, "model.safetensors")
|
| 22 |
-
if weight_path != standard_path and not os.path.exists(standard_path):
|
| 23 |
-
print(f"Создаем линк для {f} -> model.safetensors")
|
| 24 |
-
os.symlink(weight_path, standard_path)
|
| 25 |
-
break
|
| 26 |
-
except Exception:
|
| 27 |
-
continue
|
| 28 |
-
|
| 29 |
-
print("Загрузка OrionPax в память сервера...")
|
| 30 |
model = LlamaForCausalLM.from_pretrained(
|
| 31 |
-
|
| 32 |
torch_dtype=torch.float16,
|
| 33 |
-
|
|
|
|
| 34 |
)
|
| 35 |
|
| 36 |
def generate(text):
|
|
@@ -42,19 +26,19 @@ def generate(text):
|
|
| 42 |
with torch.no_grad():
|
| 43 |
output = model.generate(
|
| 44 |
**inputs,
|
| 45 |
-
max_new_tokens=
|
| 46 |
temperature=0.7,
|
| 47 |
do_sample=True
|
| 48 |
)
|
| 49 |
|
| 50 |
return tokenizer.decode(output[0], skip_special_tokens=True)
|
| 51 |
|
| 52 |
-
# Интерфейс Gradio
|
| 53 |
demo = gr.Interface(
|
| 54 |
fn=generate,
|
| 55 |
inputs=gr.Textbox(lines=3, placeholder="Напиши что-нибудь OrionPax..."),
|
| 56 |
outputs="text",
|
| 57 |
-
title="OrionPax AI Cloud 1.0V"
|
| 58 |
)
|
| 59 |
|
| 60 |
demo.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import LlamaForCausalLM, LlamaTokenizer
|
|
|
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# Указываем твое новое правильное имя репозитория моделей
|
| 6 |
+
model_id = "AxisCommunity/OrionPaxAI_1.0V"
|
| 7 |
|
| 8 |
+
print("Загрузка токенизатора для OrionPax...")
|
| 9 |
tokenizer = LlamaTokenizer.from_pretrained(model_id)
|
| 10 |
|
| 11 |
+
print("Загрузка весов OrionPax (включаем экономию ОЗУ)...")
|
| 12 |
+
# Метод автоматически найдет файл orion_model.safetensors, так как он один в репо
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
model = LlamaForCausalLM.from_pretrained(
|
| 14 |
+
model_id,
|
| 15 |
torch_dtype=torch.float16,
|
| 16 |
+
low_cpu_mem_usage=True, # Это спасет бесплатный сервер от зависания памяти!
|
| 17 |
+
device_map="auto" # Автоматическое распределение
|
| 18 |
)
|
| 19 |
|
| 20 |
def generate(text):
|
|
|
|
| 26 |
with torch.no_grad():
|
| 27 |
output = model.generate(
|
| 28 |
**inputs,
|
| 29 |
+
max_new_tokens=100, # Оптимально для быстрой генерации в облаке
|
| 30 |
temperature=0.7,
|
| 31 |
do_sample=True
|
| 32 |
)
|
| 33 |
|
| 34 |
return tokenizer.decode(output[0], skip_special_tokens=True)
|
| 35 |
|
| 36 |
+
# Интерфейс Gradio
|
| 37 |
demo = gr.Interface(
|
| 38 |
fn=generate,
|
| 39 |
inputs=gr.Textbox(lines=3, placeholder="Напиши что-нибудь OrionPax..."),
|
| 40 |
outputs="text",
|
| 41 |
+
title="OrionPax AI Cloud 1.0V"
|
| 42 |
)
|
| 43 |
|
| 44 |
demo.launch()
|