AxisCommunity commited on
Commit
c0bd45a
·
verified ·
1 Parent(s): 9a3afc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -23
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
- .gr-container {
19
- background: rgba(0, 0, 0, 0.7) !important; /* Темный фон для чата, чтобы текст сиял */
20
- border-radius: 15px;
21
  border: 1px solid #00FFFF;
 
22
  }
23
  .quality-text {
24
- color: #00FFFF; /* Яркий бирюзовый, будет отлично виден */
25
- text-shadow: 0 0 10px #00FFFF;
26
  font-weight: bold;
27
- font-size: 30px;
28
  text-align: center;
29
- padding: 10px;
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"User: {message}\nAssistant:"
38
 
39
- # Генерируем ответ
40
- output = generator(prompt, max_new_tokens=50, do_sample=True, temperature=0.7)
41
- answer = output[0]['generated_text'].split("Assistant:")[-1].strip()
42
 
 
 
 
43
  return answer
44
 
45
- # 4. ЗАПУСК ТЕРМИНАЛА
46
- with gr.Blocks(css=css) as demo:
47
  gr.HTML("<div class='quality-text'>PROJECT AXIS: EVOLVED AI</div>")
48
-
49
  gr.ChatInterface(
50
  fn=axis_chat,
51
- description="Система прошла мгновенное обучение. Мозги: SmolLM-Instruct."
52
  )
53
 
54
  if __name__ == "__main__":
55
- demo.launch()
 
 
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)