AugustLight commited on
Commit
32b5fa7
·
verified ·
1 Parent(s): 0062f54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -45,23 +45,26 @@ def respond(message, history, system_message, max_new_tokens, temperature, top_p
45
 
46
  print(f"Генерируем ответ для контекста длиной {len(context)} символов")
47
 
48
- response = model(
 
49
  prompt=context,
50
  max_tokens=max_new_tokens,
51
  temperature=temperature,
52
  top_p=top_p,
53
  stop=["User:", "\n\n", "<|endoftext|>"],
54
- echo=False # Не возвращать промпт в ответе
55
- )
56
-
57
- generated_text = response['choices'][0]['text']
58
- print(f"Ответ сгенерирован успешно, длина: {len(generated_text)}")
59
- return generated_text.strip()
 
 
60
 
61
  except Exception as e:
62
  error_msg = f"Произошла ошибка: {str(e)}"
63
  print(error_msg)
64
- return error_msg
65
 
66
 
67
  demo = gr.ChatInterface(
@@ -93,8 +96,8 @@ demo = gr.ChatInterface(
93
  label="Top-p (nucleus sampling)"
94
  ),
95
  ],
96
- title="GGUF Chat Model",
97
- description="Чат с GGUF моделью (LLight-3.2-3B-Instruct)",
98
  examples=[
99
  ["Привет! Как дела?"],
100
  ["Расскажи мне о себе"],
 
45
 
46
  print(f"Генерируем ответ для контекста длиной {len(context)} символов")
47
 
48
+ # Используем генерацию с потоком
49
+ for response in model(
50
  prompt=context,
51
  max_tokens=max_new_tokens,
52
  temperature=temperature,
53
  top_p=top_p,
54
  stop=["User:", "\n\n", "<|endoftext|>"],
55
+ echo=False, # Не возвращать промпт в ответе
56
+ stream=True # Включаем потоковую передачу
57
+ ):
58
+ generated_text = response['choices'][0]['text']
59
+ print(f"Промежуточный ответ: {generated_text}")
60
+ yield generated_text # Отправляем промежуточный результат
61
+
62
+ print("Ответ сгенерирован полностью.")
63
 
64
  except Exception as e:
65
  error_msg = f"Произошла ошибка: {str(e)}"
66
  print(error_msg)
67
+ yield error_msg
68
 
69
 
70
  demo = gr.ChatInterface(
 
96
  label="Top-p (nucleus sampling)"
97
  ),
98
  ],
99
+ title="Llight Chat",
100
+ description="Чат с LLight-3.2-3B-Instruct",
101
  examples=[
102
  ["Привет! Как дела?"],
103
  ["Расскажи мне о себе"],