Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,54 +2,54 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# 1. ЗАГРУЗКА
|
| 6 |
-
# Используем легкую модель, которая быстро соображает
|
| 7 |
model_name = "HuggingFaceTB/SmolLM-135M-Instruct"
|
| 8 |
device = 0 if torch.cuda.is_available() else -1
|
| 9 |
generator = pipeline("text-generation", model=model_name, device=device)
|
| 10 |
|
| 11 |
-
# 2. ДИЗАЙН (
|
| 12 |
css = """
|
| 13 |
-
footer {visibility: hidden}
|
| 14 |
body {
|
| 15 |
background: linear-gradient(135deg, #FF00CC 0%, #9932CC 40%, #0000FF 70%, #00FFFF 100%) !important;
|
| 16 |
background-attachment: fixed;
|
| 17 |
}
|
| 18 |
-
.
|
| 19 |
-
background: rgba(0, 0, 0, 0.7) !important;
|
| 20 |
-
border-radius:
|
| 21 |
border: 1px solid #00FFFF;
|
|
|
|
| 22 |
}
|
| 23 |
.quality-text {
|
| 24 |
-
color: #00FFFF;
|
| 25 |
-
text-shadow: 0 0
|
| 26 |
font-weight: bold;
|
| 27 |
-
font-size:
|
| 28 |
text-align: center;
|
| 29 |
-
|
| 30 |
}
|
| 31 |
-
p, span, label { color: white !important; font-size: 16px; }
|
| 32 |
"""
|
| 33 |
|
| 34 |
-
# 3. ЛОГИКА
|
| 35 |
def axis_chat(message, history):
|
| 36 |
-
#
|
| 37 |
-
prompt = f"
|
| 38 |
|
| 39 |
-
# Генери
|
| 40 |
-
output = generator(prompt, max_new_tokens=
|
| 41 |
-
answer = output[0]['generated_text'].split("Assistant:")[-1].strip()
|
| 42 |
|
|
|
|
|
|
|
|
|
|
| 43 |
return answer
|
| 44 |
|
| 45 |
-
# 4. ЗА
|
| 46 |
-
with gr.Blocks(
|
| 47 |
gr.HTML("<div class='quality-text'>PROJECT AXIS: EVOLVED AI</div>")
|
| 48 |
-
|
| 49 |
gr.ChatInterface(
|
| 50 |
fn=axis_chat,
|
| 51 |
-
|
| 52 |
)
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|
| 55 |
-
|
|
|
|
|
|
| 2 |
from transformers import pipeline
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# 1. ЗАГРУЗКА МОЗГА (Он уже скачан в кэш, так что будет быстро!)
|
|
|
|
| 6 |
model_name = "HuggingFaceTB/SmolLM-135M-Instruct"
|
| 7 |
device = 0 if torch.cuda.is_available() else -1
|
| 8 |
generator = pipeline("text-generation", model=model_name, device=device)
|
| 9 |
|
| 10 |
+
# 2. ДИЗАЙН (Твой градиент)
|
| 11 |
css = """
|
|
|
|
| 12 |
body {
|
| 13 |
background: linear-gradient(135deg, #FF00CC 0%, #9932CC 40%, #0000FF 70%, #00FFFF 100%) !important;
|
| 14 |
background-attachment: fixed;
|
| 15 |
}
|
| 16 |
+
.gradio-container {
|
| 17 |
+
background: rgba(0, 0, 0, 0.7) !important;
|
| 18 |
+
border-radius: 20px;
|
| 19 |
border: 1px solid #00FFFF;
|
| 20 |
+
color: white !important;
|
| 21 |
}
|
| 22 |
.quality-text {
|
| 23 |
+
color: #00FFFF;
|
| 24 |
+
text-shadow: 0 0 15px #00FFFF;
|
| 25 |
font-weight: bold;
|
| 26 |
+
font-size: 32px;
|
| 27 |
text-align: center;
|
| 28 |
+
margin: 20px;
|
| 29 |
}
|
|
|
|
| 30 |
"""
|
| 31 |
|
| 32 |
+
# 3. ЛОГИКА УМНОГО ЧАТА
|
| 33 |
def axis_chat(message, history):
|
| 34 |
+
# Специальный формат запроса для этой модели (чтобы она не тупила)
|
| 35 |
+
prompt = f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n"
|
| 36 |
|
| 37 |
+
# Генерация ответа
|
| 38 |
+
output = generator(prompt, max_new_tokens=150, do_sample=True, temperature=0.7)
|
|
|
|
| 39 |
|
| 40 |
+
# Очищаем ответ от системных тегов
|
| 41 |
+
full_text = output[0]['generated_text']
|
| 42 |
+
answer = full_text.split("<|im_start|>assistant\n")[-1].replace("<|im_end|>", "").strip()
|
| 43 |
return answer
|
| 44 |
|
| 45 |
+
# 4. СОЗДАНИЕ ИНТЕРФЕЙСА
|
| 46 |
+
with gr.Blocks() as demo:
|
| 47 |
gr.HTML("<div class='quality-text'>PROJECT AXIS: EVOLVED AI</div>")
|
|
|
|
| 48 |
gr.ChatInterface(
|
| 49 |
fn=axis_chat,
|
| 50 |
+
type="messages" # Новый стандарт Gradio 6
|
| 51 |
)
|
| 52 |
|
| 53 |
if __name__ == "__main__":
|
| 54 |
+
# В Gradio 6.0 CSS передается именно сюда!
|
| 55 |
+
demo.launch(css=css)
|